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. Creating the folder
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.Start by creating a regular folder on the desktop; you can either right-click and select "New Folder," or select "New Folder" from the Finder's File menu.

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.
Share
Categories
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...
Add a Comment
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_
display dialog file_
end tell
end repeat
end adding folder items to
I copied and pasted above code in "Script Editor". But Will I have to save it as script or "run only app". I saved both the forms of it.
After than I right clicked a folder and selected "Attach Folder action" and selected script. Then I dragged a file. But it didn't popup any dialog for me.
Also I repeated the same with run only app. It also didn't display any dialog.
why?
I am a lazy designer and store all of my files on my desktop. At the end of the week, I run Hazel w/ my desktop folder actions and move screenshots to a folder and change their name to screenshot-yyyy-mm-dd-hh-mm-ss.png and move all my istock images to my stock photography folder. etc...
It is a great way to keep organized. Theoretically you could do the same thing w/ folder actions.
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/
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??
February 16 2009 at 9:51 PM Report abuse Permalink rate up rate down Replyyay, i like learning new things. thanksssss!
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?
February 16 2009 at 7:18 PM Report abuse Permalink rate up rate down ReplyI 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 ;-)
Why not just enable the Transmission web interface? Then you can see how far your download is at any given point.
February 16 2009 at 4:14 PM Report abuse Permalink rate up rate down Replyauto add mp3 to itunes when dropped into a folder. Use the 2nd script its sweet.
http://dougscripts.com/itunes/itinfo/folderaction01.php
Great!! This is giving me tons of innovative ideas! BTW, where do I get the script to upload the dropped files to FTP ??
February 16 2009 at 3:02 PM Report abuse Permalink rate up rate down ReplyI didn't know about this use of applescript and I've been a Mac user for a couple years. Thanks for the tip!
February 16 2009 at 2:20 PM Report abuse Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Altec Lansing Octiv Duo iDock for $48 + free shipping
- Used Apple iMac 17" Core Duo 1.83GHz for $430 + $28 s&h
- Lounge Deluxe Stand for iPhone / iPod touch for $28 + $8 s&h
- Brookstone Surround-Sound Earbuds for $14 + $7 s&h
- Refurbished Skullcandy Tokidoki Smokin' Buds Mic'd Headset for $5 + $2 s&h
- Stitchway Backup Battery for iPod / iPhone for $5 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



22 Comments