First Aid Self Service - command line to empty iPhoto trash

mahughe
Contributor

I'm looking at putting together a first aid script for self service to aid endusers to cleanup the "other" storage that is
taking up space. I have the piece pertaining to deleting .dmg/pkg's from the download/document folders, but I'd like to incorporate the iPhoto Trash into that as well, but I'm lacking the CL command to do so.

If anyone might have that piece of the puzzle or other suggestions I'm open to all..

Thanks,

2 REPLIES 2

mm2270
Legendary Contributor III

From a pure bash script point of view, doing this will be nearly impossible. The iPhoto Library bundle is a complex maze (some would call it a mess) of folders within folders, many with random names, database files, xml and properly list files and who knows what else (and that's not even counting the images which are typically split into 3 versions).
I believe that when a user "deletes" a photo in the app, all that happens is the photo gets flagged with some metadata to tell the app to hide it from the normal views and make it show up in the "Trash" link in the app. It doesn't physically move the files into some other folder that a script would be able to locate and empty. This is done for efficiency purposes. Whenever you need to move files around on disk it eats up CPU and power.

But… fortunately iPhoto has an Applescript library and it can be done with an Applescript, or from a shell script that runs Applescript command if you prefer.

I just looked up the AS dictionary and put this together,. I tested it against a smallish Trash folder in my iPhoto app. The only thing is, the app needs to launch so it will show up in the Dock of course. Using the "run" command instead of 'activate" opens it but doesn't bring it to the foreground so that's some help.
Also, the repeat loop is to help combat instances where the script could get ahead of the app launching and fail to delete the Trash. You might need to adjust this some more. test it out and see.

tell application "iPhoto"
    run
end tell
repeat 5 times
    try
        tell application "iPhoto" to empty trash
        exit repeat
    on error
        delay 3
    end try
end repeat
tell application "iPhoto" to quit

As I said, in my test it worked. Launched iPhoto (in the background) sat there for a few moments, emptied the Trash (the icon bounced in the Dock as this happened), then quit silently.

Of course, if a user has iPhoto open when this runs it will still quit it when its done, so just something to keep in mind. But since this would be a Self Service policy, it may not be an issue. Just send up a message before it runs that it will delete "trashed" photos and quit iPhoto when its done.

mahughe
Contributor

@mm2270 sorry for the delay getting back to you on this...I'll give it a try, and hopefully incorporate it into
the plan, thanks again..