testing vs. documentation

I have made some progress on my automatic ipod transfer script

The first step is to set Nautilus (that’s the file browser in the Gnome desktop) preferences, since it is the program which deals with automatically mounting media. So in Nautilus->Edit->Preferences->Media I set the ‘Media Handling’ for ‘Music Player’ to run a script of my choice when the ipod is connected.

The next step was finding a Python script in the python-gpod examples directory which just copies over some files to an ipod – so I copied and tweaked that. (I don’t write Python very much, but I can just about understand a short existing script).

Because I’m not comfortable with Python, I wrote a Bash script to be the real driver. So it is called by Nautilus when the ipod is connected, and it finds the podcasts I want to copy over, and calls the Python script just to add them.

Originally, I hardcoded the ipod mount point into the Bash script. This will be fine on my systems, but it seemed a little silly – I was convinced that Nautilus must pass the mount point somehow to the programs it starts, otherwise in general they would have trouble deciding what to do. Unfortunately I couldn’t find any documentation on how the script would be started.

The alternative to reading documentation is testing and seeing what happens. So I wrote a script which just appends it’s arguments and environment variables into a file. I set this up as the program for Nautilus to run, and connected the ipod, then looked in my log file. Sure enough, the first (and only) argument to the test program was the path of the mount point. So now I can use that in my real script, and it will be a bit more flexible.

Just a little reminder of a point I’ve mentioned before – writing a small test script and seeing what happens is often easier and quicker than reading documentation to find out what should happen.

Post a Comment

Your email is never published nor shared. Required fields are marked *