Hello,
It's now past 1.5 years as I'm trying to build a simple workflow in the form of a folder action: once photos of acceptable formats arrive in "Downloads" folder import them to iPhoto (using iLife '11 and am on 10.7.5 , "Lion"). Havin learned much over this time span about AppleScript as well as Automator I returned to my unrefined workflow and now it has this actions:
- Folder action is attached to folder "Downloads"
- The actions:
- Set value of variable (stores references to photos arrived in "Downloads" folder). I named this variable "Photos downloaded"
- Get value of variable set in step 1. Parameters: receives no input, because passes it to the next action just for that action.
- Run AppleScript. The script determines (parses references, grabs extension's part of the reference, verifies if it's one of "jpg, jpeg") if the files are photos. If no the whole workflow halts, if yes, then proceeds further. The script's body's below:
- on run {input, parameters}
tell application "Finder" set theList to input set POSIXfiles to {} repeat with i from 1 to (count theList) set end of POSIXfiles to POSIX path of item i of theList end repeat POSIXfiles set FileExtensions to {} repeat with j from 1 to (count POSIXfiles) set TheItem to item j of POSIXfiles set AppleScript's text item delimiters to "/" set BaseName to text item -1 of TheItem set theDot to offset of "." in BaseName set MyExtension to text (theDot + 1) thru -1 of BaseName set end of FileExtensions to MyExtension end repeat FileExtensions ignoring case set AcceptableFormats to {"jpg", "jpeg"} end ignoring if some item of FileExtensions is not in AcceptableFormats then tell application "System Events" to set enabled of folder action "Downloads" to false end tell end run
- Get value of variable (the same value as in step 2), receives no input, passes references to the next action which is
- Import to iPhoto. Receives input from step 4. The new values on output of the current action are then stored in a new variable, hence
- Set value of variable. Receives input. Stores references to imported photos. I named this variable "Photos imported"
- Get value of variable (the same value as in step 6), receives no input, stores references to imported photos only to pass it to the next action which is
- Run AppleScript. It acquires references from the previous action and transforms them into a set of filenames of the imported files, formatted as a textual list. The script's body:
- on run {input, parameters}
tell application "iPhoto" set PhotoNames to {} repeat with i from 1 to (count input) set end of PhotoNames to name of contents of item i of input end repeat PhotoNames set AppleScript's text item delimiters to return return PhotoNames as text end tell end run
- The formatted text was necessary to pass it to the last action Show Growl Notification (which Mountain Lion onwards with its Notification Center has built-in OS X analogue of named "Show Notification") to appear as annotation in the form of list of the filenames imported, beneath the main text of the Growl's notification banner, which is customizable feature and I scribbled smth like "Success on import. Your photos are now in iPhoto Library" .
It works fine but only on one-file-at-a-time basis. I originally thought it out to let my photos from Android phone flow via bluetooth to Downloads and then this fold action would sping to life and the rest of the job. Unfrotunately it processes only the first file arrived but falls asleep just as it's done with it. After some time I accidentally discovered the actions mentioned in the subject of this thread on Sal's website macosautomation.com. The description of "Wait fir files..." reads: "This action will wait for files...to finish being copied into their containing folder. Place this action at the beginning of the workflow that will be saved as a Folder Action plugin ." I placed it at the beginning to no avail. Then there was "DIspence items..incrementally", its annotation tells us: "the actions is used to take Finder items and process then one-at-a-time. To use place this action after an action that passes references to disk Finder items such as Get Selected Finder items or Select Specified Finder items. The disk item references passed by this actions will be dispensed individually by this action as the workflow loops". I placed "Loop" at the end of my folder action workflow and placed "Dispense" alternatively before step 1, after step 2. For testing purposes I added "Get Specified Finder items" and added several jpg files of "Downloads" folder. I then added "Wait for files..." before step 1 (rearranging the workflow a bit so that "Dispence" was right before "Import to iPhoto"). This time it worked processing "incrementally" every fed item but only trailed with "Get specified" action with target files consolidated in a single group. I feel that with these two actions that's where the shoe pinches but I'm not sure whether I can accomplish my goal in Automator (even if using AppleScript's injections which I absolutely fine with), whether these actions can help. Question remains: Regardless what I wrote how are they supposed to work and in a what possible context? How do I make my workflow to collect the photos being arrived one by one during some length of time, i.e., how do I make the folder action to trigger itself every time the photo downloads? |