Filed under: Features, AppleScript
AppleScript: Exploring the power of Folder Actions, part I
Welcome to Part I of this mini AppleScript feature on creating useful folder actions. We'll have more posts on this topic coming up, but for now, let's introduce what a folder action is. Have you ever wanted to just drop a file into a folder and have something magically happen? Say, have a file printed, whisked to a remote site via FTP, or perhaps have an image be automatically flipped from horizontal to vertical? With Mac OS X's built-in folder actions, you can easily do this with a simple drag and drop. First, let's talk about how we can enable these "magical folders" that perform actions on files dropped within them. For this example, I'll show you how to make a folder on your desktop that, when a file gets dropped into it, will display a dialog letting your know that the file was placed there.

A menu will roll down asking you to specify an Apple-created script. We'll choose the "add - new item alert.scpt." This script will alert the user via a dialog when an item is placed in a specific folder. In the right hand side of the window you will now notice that the add script has been placed there. You can add multiple scripts to a folder action and they will be performed in consecutive order until the end of the list is reached. Once you have created the actions, you can close the window.
It's just a drag to the left.... activating the scripts
With the folder now set up to accept drag and drops, you can drag a file onto it. In a few seconds (depending on the copy time), you'll see a dialog popup on your screen alerting you that your file has just been copied into this folder. Pretty neat, huh?I tend to use this same folder action for my Drop Box located in the public directory of my user account. Since this folder is available to the public via a LAN connection, I am alerted whenever someone drops a file into it. There are literally tons of uses for the add file folder action. Why not play around with it and let us know your favorite uses for it?
Coming up in Part II: we'll go through Apple's supplied folder scripts and identify which of them provide the maximum automation payoff.

![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 2)
jason mark said 12:15PM on 2-16-2009
I was able to find a copy of the apple supplied script you refer to, but it won't let me select it (grayed out)....
Reply
Aaron Eiche said 1:01PM on 2-16-2009
A while back I setup a folder Action for uploading pictures to my website. I set it up to drag and drop it in, upload the file, and then delete it. My only problem really is that the upload is not reliable. Sometimes it works, sometimes it doesn't.
Other than that, I think folder actions are brilliant, and my only want would be that it was more intuitive to set them up.
Reply
BobbyW said 1:19PM on 2-16-2009
Automatically email a file dropped into a Finder folder to a preset address....
http://murphymac.com/new-and-improved-finder-emailing/
Reply
Tom said 1:45PM on 2-16-2009
If you want a folder action to automatically put all your videos in iTunes (even AVI and MKV) after downloading, have a look at www.aroona.net. It even has the option to move them too so you can create a video inbox folder. .
Reply
Kevlar said 2:06PM on 2-16-2009
I use folder actions for my Downloads folder. Items that are added are "touched" so that the last-modified date reflects the date/time they were added to the folder. This let's me sort my downloads folder by most recent.
Having the most recent file you downloaded at the top is really quite fantastic. Also by making a stack of this folder, I can have a properly ordered Downloads stack even when I don't use Safari!
Reply
ChriB said 2:41PM on 2-16-2009
I would love to see this script! :)
Kevlar said 2:58PM on 2-16-2009
on adding folder items to this_folder after receiving added_items
repeat with file_ in added_items
tell application "Finder"
set file_ to POSIX path of file_
do shell script "touch -c " & quoted form of file_
end tell
end repeat
end adding folder items to
ChriB said 3:10PM on 2-16-2009
Thank you. Works perfectly!
dagamer34 said 2:08PM on 2-16-2009
Can this be used to have Growl alerts instead? I think those would be less intrusive.
Reply
Kevlar said 3:02PM on 2-16-2009
YES! Growl and AppleScript work very well...
See: http://growl.info/documentation/applescript-support.php
You can pop a growl notification instead of an alert box.
Bakari said 4:26PM on 2-16-2009
This is great, and I use them often. But just want to add for those who are too timid to create AppleScript scripts, a little application called Hazel does pretty much the same thing.
Reply
JohnQ said 2:21PM on 2-16-2009
I didn't know about this use of applescript and I've been a Mac user for a couple years. Thanks for the tip!
Reply
Jash Sayani said 3:02PM on 2-16-2009
Great!! This is giving me tons of innovative ideas! BTW, where do I get the script to upload the dropped files to FTP ??
Reply
dada said 3:21PM on 2-16-2009
auto add mp3 to itunes when dropped into a folder. Use the 2nd script its sweet.
http://dougscripts.com/itunes/itinfo/folderaction01.php
Reply
Greg said 3:47PM on 2-16-2009
I use folder actions for two thinks :
- Adding Google Analytics code to the websites created with iWeb once uploaded to mac web server. I use an automator script for that purpose (http://www.apple.com/downloads/macosx/automator/addgoogleanalyticsaction.html)
- Downloading Linux distributions remotely using dropbox : First I download the .torrent file with my laptop at work. Once downloaded, the .torrent is detected by a folder action then moved to a special folder in my dropbox. When synced to my mac at home, another folder action detects the .torrent file and moves it to another folder whatched by Transmission. The download starts and I can burn the Linux DVDs once back home. (And Yes, I like chain reactions ;-)
Reply
Kevlar said 4:14PM on 2-16-2009
Why not just enable the Transmission web interface? Then you can see how far your download is at any given point.
Flo said 7:19PM on 2-16-2009
The problem with those folder actions (and with Hazel afaik) is, there is no way to include (i.e. extend the action to) sub folders. So if you create a sub folder in your desktop folder and a file is being added there, you won't get any alert box. Or am I missing something?
Reply
julian said 7:59PM on 2-16-2009
yay, i like learning new things. thanksssss!
Reply
jacjos7 said 9:56PM on 2-16-2009
Can same folder action be configured for all the child (nested) folders as well. I mean for example, I want to add files to iTunes when I copy those files to a particular folder or its existing or new child folder/s... can I achieve this using applescript/folder actions??
Reply
jxn said 7:38AM on 2-17-2009
I wrote a similar article about file sharing and notifications just one day before yours. Weird.
http://www.makeuseof.com/tag/establish-file-sharing-notifications-between-networked-macs/
Reply