Help me write a script in OSX
October 26, 2009 9:54 AM Subscribe
How do I create a file-handling script in OSX?
I want to create a script that will throw whatever is in my CF card in the trash, empty the recycle bin and then eject the card.
I frequently transfer pictures from my card to my computer and with lightroom 2 they don't automatically erase off the card so I need to do it by hand.
I find that if I trash the files on the card and DON'T empty the recycle bin the data stays held up in the card and eventually have to format it.
Are there any other options? If not, how would I write a script. I tried "recording" a script in Applescript Editor but that didn't work at all.
Thanks!
I want to create a script that will throw whatever is in my CF card in the trash, empty the recycle bin and then eject the card.
I frequently transfer pictures from my card to my computer and with lightroom 2 they don't automatically erase off the card so I need to do it by hand.
I find that if I trash the files on the card and DON'T empty the recycle bin the data stays held up in the card and eventually have to format it.
Are there any other options? If not, how would I write a script. I tried "recording" a script in Applescript Editor but that didn't work at all.
Thanks!
AppleScript is a quirky language, and can be hard to use even for a professional programmer. But for simple things like this it does pretty well. Here's a script that does what you want, assuming you know the name of your disk ahead of time:
posted by serathen at 3:59 PM on October 26, 2009
tell application "Finder" set CFDisk to disk "My CF Disk Name" delete items of CFDisk empty trash -- Danger Will Robinson! eject CFDisk end tellThis too is a little unsafe, since it will empty the trash (for all disks) without asking confirmation. Here's one that does:
tell application "Finder" set itemsInTrash to (number of items of trash) set CFDisk to disk "My CF Disk Name" if (itemsInTrash > 0) then (* Undocumented subtlety here: we get OK and Cancel by default, and hitting cancel aborts the script *) display dialog (itemsInTrash as string) & " items already in trash will be erased. Proceed?" end if delete items of CFDisk empty trash eject CFDisk end tellI've tested the above scripts, but offer no warrantee.
posted by serathen at 3:59 PM on October 26, 2009
This thread is closed to new comments.
posted by mkb at 9:59 AM on October 26, 2009