I wanted to write a script to eject my iPod from the keyboard, since the multi-step process with iTunes was a bit convoluted and my desktop is often obscured. But first, I downloaded Apple's iPod Scripts which happily included such a script. I ran the script, and it crashed:
#0 0x9022e158 in FSRefLookupMount(FSRefPrivate const*)
#1 0x00000000 in 0x0
#2 0x902309b4 in PBGetCatalogInfoBulkSync
#3 0x90243518 in FSGetCatalogInfoBulk
#4 0x03092b18 in AEVTearslfdr(AEDesc const*, AEDesc*, unsigned long)
#5 0x91b56570 in aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned long, unsigned char*)
#6 0x91b5a8e4 in sendToSelf(AEDesc const*, AEDesc*, long, long)
#7 0x91b58124 in AESendMessage
AppleScripts are meant to do many wonderful things, notably not including crashing the host application. I gave up at the time, but when I found the same problem in the “Create Note from Clipboard” script from which I'm borrowing to write my Palm Desktop note/memo sync script, I tracked the problem down to this handler:
on locate_iPods()
set the volumes_directory to “/Volumes/” as POSIX file as alias
set the volume_names to list folder volumes_directory without invisibles
set mounted_iPods to {}
repeat with i from 1 to the count of volume_names
try
set this_name to item i of volume_names
set this_disk to (“/Volumes/” &this_name & “/“) as POSIX file as alias
set these_items to list folder this_disk
if “iPod_Control” is in these_items then
set the end of the mounted_iPods to this_disk
end if
end try
end repeat
return mounted_iPods
end locate_iPods
The above seemed like an awful lot of work to list the mounted disks. Somehow I've got an 82-byte file named “._Nikon_photo” (the volume name of my camera's CompactFlash card) in my /Volumes directory, and since the AppleScript definition of “without invisibles” doesn't include UNIX “dotfiles” such as this one, it showed up in the mounted volume list. The “list folder” scripting addition, annoyingly, crashed when it was asked to list something that wasn't a folder, and that was that.
The weird thing is that, listed right about the “list folder” script addition is “list disks”, which allows you to simplify the script to the following:
on locate_iPods()
set mounted_iPods to {}
repeat with this_disk in list disks
set these_items to list folder (this_disk as alias)
if “iPod_Control” is in these_items then
set the end of the mounted_iPods to (this_disk as alias)
end if
end repeat
return mounted_iPods
end locate_iPods
This version of the handler has the advantages of being easier to read, and not crashing. All the iPod scripts have this handler in them, so just copy and paste the above into them.
Of course, I can't find anywhere to send feedback for the scripts. Hence this weblog entry, in the hope that someone, somewhere will read it.