Friday, October 30, 2009

One Liner: Synchronize Digital Camera Clock

The clock on my Canon Powershot A620 is yet another clock that I want to synchronize with my PC.

Hook the camera over USB to the PC and run:
gphoto2 --set-config /main/settings/synctime=1
Use the following to read the camera clock and verify that it's synchronized:
gphoto2 --get-config /main/settings/time
(requires gphoto2)

Friday, October 23, 2009

Wine and Missing MFC42.DLL

Every once in a while I need to run a Window$ application. If the application at hand is a standalone application that does not require installation, I'll usually attempt to run it first with Wine, instead of launching a full blown WinXP virtual machine.

Using Wine is a no brainer:
wine /path/to/application.exe <command-line-arguments>
and if the file happens to have executable permissions (chmod +x ...) then it's even easier - just launch it like any other script or binary executable, by typing
/path/to/application.exe <command-line-arguments>
Last time I tried it I hit a problem:
err:module:import_dll Library MFC42.DLL (which is needed by L"Z:\\path\\to\\application.exe") not found
err:module:LdrInitializeThunk Main exe initialization for L"Z:\\path\\to\\application.exe" failed, status c0000135
This means that a required DLL is missing - in this case it's MFC42.DLL. This specific DLL is needed for (older) GUI applications that use MFC, and it isn't part of Wine.

Whatever you do if this happens to you - don't try getting this DLL from any of the websites that Google will list when you search for it. Google marks quite a few of these sites as sites that can harm your computer. You have been warned.

Window$ users can get MFC42.DLL and other DLLs by installing the Microsoft Visual C++ Redistributable Package.

The recommended way of doing this under Wine is to follow the instructions on the Wine wiki:
  1. download winetricks:
  2. make it executable:
    chmod +x winetricks
    (optional: place the file in a system directory such as /usr/local/bin)
  3. install cabextract:
    aptitude install cabextract
    (actually, I'm not sure it's necessary for fixing the MFC problem, but it's definitely recommended for fixing other Wine problems)
  4. run
    winetricks mfc42
The winetricks script has lots of other options for fixing a host of issues and installing a rather long list of third party packages that are not part of Wine.

Bottoms Up!

[25 Feb 2012] UPDATE: winetricks has been packaged in Debian/testing for quite a while - so I recommend that you don't install it manually as per steps 1 thru 3 above, but rather use one of the package managers to do it for you:
aptitude install winetricks

Friday, October 16, 2009

It Works. Again. (or: ZIP Archives and non-English Filenames)

The wait is over. My wife's laptop came back from the lab. They've replaced the motherboard. Again.

My wife has commandeered my laptop during the past few weeks, trying to get some work done on a VirtualBox hosted WinXP machine, with her My Documents folder pointing to a VirtualBox shared folder in my home directory.

She wasn't happy: I think that the virtual machine is surprisingly fast; she thinks that it's dead slow.

Anyway, the bottom line is that she did manage to modify a few documents and created several new ones. So all that remained to be done, before reverting my laptop to its Debian self, was to synchronize between the My Documents folder on the fixed laptop and the documents directory on my laptop's hard drive.

I used the following to create a ZIP archive containing only the files that my wife modified recently:
cd ~/docs/wife/                                              
find -newermt "Sep 23 2009" | grep -v Thumbs.db | grep -v Desktop.ini | zip -@ /tmp/
My intention was to copy this archive over to my wife's laptop and extract its contents to her My Documents folder.

Unfortunately, the Unicode encoded file names in the archive showed up as garbage when the archive was opened on the Window$ box. So I re-archived the files with 7zip (Debian package p7zip-full), which seems to handle non-English file names in a more sensible manner:
mkdir /tmp/wife-docs
cd /tmp/wife-docs
unzip ../
7z a ../wife-docs.7z .
Next time (hopefully never - but I don't kid myself) I'll probably mount my wife's documents folder over CIFS and then use rsync to synchronize the files. It's supposed to be The Right Way™ to do this.

The warranty on my wife's laptop expires in a month. Wish us luck.

Friday, October 9, 2009

Synchronize HP Printer/Fax Clock

After the stellar success of my cellular phone clock synchronization script, I had an idea: why not synchronize the printer clock too?

We have an HP OfficeJet 5510 printer/fax/scanner/copier combo, which is hooked directly to my laptop over USB. Its front panel clock tends to drift quite a bit, and I usually forget to switch it from/to Daylight savings time.

It took about two minutes to find hp-timedate, and here's the corresponding cron job specification:
 10 4    *   *   *   /usr/bin/hp-timedate
Now, how do I interface my laptop with the microwave oven?

Friday, October 2, 2009

Synchronizing Cellular Phone Date and Time with Gammu

After becoming the proud owner of a Bluetooth to USB adaptor, I started looking around for a way to automate the backup process of our cellular phones.

I've installed Wammu and was pleasantly surprised by how easy it was to get it up and running. But as soon as I had it configured to talk with both our phones, I realized that what I really wanted was to use Gammu, its command line alter ego.

My plan is to run a backup script every night that will copy contents and settings from the phones to my laptop over Bluetooth. I'll post my backup script as soon as it's up and running for a few days.

In the meantime, let me present another script that I run as a scheduled task every night. It's job is to synchronize the date and time on both our phones to the laptop clock. This has several benefits:
  1. the phone clocks are more accurate (because the laptop clock is updated by NTP)
  2. the phone clocks switch automatically to and from Daylight savings time,
  3. the phone clocks become synchronized to each other
And here it is:

#! /bin/bash
grep port= ~/.gammurc | cut -d= -f2 |
while read phone
name="$(grep -m $(( $section + 1 )) name= ~/.gammurc | tail -1 | sed s/name=//)"
echo $name
gammu -s $section setdatetime
let section++

I run the script as a Cron job at 4:05 AM. The idea is to synchronize clocks after 2:00AM, which is when the switch to/from Daylight savings time occurs where I live:
  1. launch crontab:
    crontab -e
    this should launch a text editor (you can configure which one by modifying the EDITOR environment variable)
  2. add the following line
      5 4    *   *   *   /full/path/to/
  3. save the file and exit the editor