AppleScript: Automating with folder actions on a Mac

30Sep08

I’ve done some Windows-only stuff on this blog already, but I own a Mac, so it’s about time I do something for my homies out there running OSX.

Breaking from the tools that would normally have you launching a Terminal, I’m going to direct your attention to AppleScript. As you might gather, AppleScript is Apple’s own scripting language for OSX, but its real power is that it’s a cinch for a developer to make their applications work with it. What does this mean for you? Oh, just that almost any OSX application can be automated. Even Photoshop (PDF warning!).

If you’re a heavy computer user (and what else would you be if you’re reading this blog?), you can probably think of a few tasks in your daily work flow that could benefit from automation. So as not to limit the utility of this though, let’s talk specifically about Folder Actions.

Folder Actions is a cool built-in tool that allows you to attach an AppleScript to a specific folder on your computer. Then, depending on how you write your script, you can have your script do things automatically when items are added or removed from that folder, or when that folder is opened, closed or moved.

The syntax is fairly simple, if not verbose:

on adding folder items to my_folder after receiving items
    repeat with file in items
         -- do stuff with "file"
    end repeat
end adding folder items to

To illustrate some of what’s possible here, I ran into a post showing how to script scanning files with Sophos, a popular anti-virus program, once they’re dropped into a specific folder. Another cool script comes from Mac OSX Hints, which is a great resource for these kinds of things, showing you how to automatically resize images.

My favorite, though, has to be a script that comes by default with Cyberduck — a good, free FTP client — that allows you to automatically upload files. Given that Cyberduck supports Amazon’s S3, you could write a script that can turn a folder on your computer into a portal to nigh-unlimited storage. If you work with people afraid of using FTP (I’ve met a few), you could use this script to allow them to simply drop files into a local folder for uploads. Combined with some other scripts, like file conversion, renaming and image resizing, you might start to see how using AppleScript and Folder Actions could really benefit your work flow.

OSX actually comes with a few scripts pre-installed, such as image conversion. I found a great visual tutorial to help you get started by playing with the built-in scripts.

Happy scripting!

Advertisements


No Responses Yet to “AppleScript: Automating with folder actions on a Mac”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: