HI guys, I read a recent post on this thread concerning workaround and fixes to the original issue of applescripts with handlers on adding folder items to ... after receiving ("FolderActions not working" or in other cases NOT responding or erratically responding / stalling , or performing erraticlly or generally problematic when invoked under OSX 10.8.x to folders.
From my research, diagnosis and experimentation I have resolved a simple procedure and change to the method of implementing FOLDER ACTIONS on OSX 10.8 and beyond, that does NOT involve directly adding FOLDER action scripts through the FINDER and also NOT the "ADD FOLDER ACTION" service or the applescript directive eg
attach action to (action_01_folder as string) using (script_01 as string) -- attach the folder action script to the folder
... and what you might try before reaching for a welder, a hammer and a scalpel (and many other things in this thread and many others in these forums) to perform some kind of low level change to stage information parms. You definately DONT need to.... 🙂
Franky this stuff should work reliably and in fact it does quite well.
I have several workflows that Ive developed over many years that rely on FOLDER ACTIONS for producing VFX and videos etc. Compressor, , Shake etc that rely on apple scripts that we rely on for production work.
you will see a great deal of messages (and strings) for FOLDER ACTIONS in the /var/log such as:
..... 20:12:47 mac-mini-i7 com.apple.launchd.peruser.501[xxx] (com.apple.FolderActions.folders): Throttling respawn: Will start in 7 seconds
... some is "is deprecated " .. etc etc
Fundamentally your applescripts are slow to repsond/trigger to an adde or removed items and in additoin a long running script completes but will not continue its iteration through a loop (repeat with items in ..) for example. Attempts to trigger it remain allusive other than loggng in and out and then local ~/Library/scripts will be enabled somehow through Launchd and they can be started.
Basically its all erratic.
1) Use Automator.app FOLDER ACTIONS to add folder actions applescript to a folder.
2) DONT use the FINDER "add folder actions" service and DONT use the applescript directive "attach action to" in applescript
3) use Automator to add your applecript to a folder as a "Folder Action" workflow:
add you VERY SLIGHLY modified (change the handler) to the "run applescript" workflow node in Automator
direct the folder action node to the FOLDER that you want the event/trigger to happer.
change the legacy applescript event hander from "on adding folder items to ... after receiving" to the default "on run {list_if_added_items, some_parms} .... .... end run" that is used in the Automator.app "Run Applescript" workflow node.
the first paramater thats passed is a LIST of pointers to the items tha were added to the folder. same as usual
parmeter 2 is a list of the TEXT script commands code and other details he was passed to this handler...
whats missing ?..... add this line of applescript to DERIVE the path of the folder where the folder action workflow is attached: tell application "System Events" to set my_hot_action_folder to the path of the container of the first item of list_of_added_items as alias
simple!
- Is well documented (Aple dev doc I recall) and these forums that launchd is the preferred method such several verisons back for kicking over folder action projects. In addition the stability of Automator.app and its interation with launchd is very solid.
- It (this) IS very stable and VERY VERY resposive compared with the legacy "on adding folder items to nnnnn after receiving yyyy" handler method as far as I have experienced.
- Automator "on run" handler from the Automator setup LAuchagents (see ~/Library/Workflows/Applications/Folder Actions" for these Folder Actions created by Automator.
- You wont see any of the "deprecated" call messages in the log unless you have some thing very old and unsupported in your applescript.
- you won't see (very much) iterative (loop /repetive contsructs) stop or pause in a long running script (say a transcoder app in a shell (do shell) or such).. the folder action script willcomplete to the end and not stall 🙂
- you MUST develop some kind of external logging and use ERROR recovery "try .. on error .. end try" constructs to catch errors. Else it very very difficult to debug these.
- DONT have any carriage returns or "blank lines" at the start of the script else you will get messages such as
"AppleScript Runner[nnnn]: Incorrect NSStringEncoding value 0x8000100 detected. Assuming NSStringEncodingASCII. Will stop this compatiblity mapping behavior in the near future." or
"AppleScript Runner[nnnnn]: CPSGetFrontProcess(): This call is deprecated and should not be called anymore."
Summary:
This approach to using Automator.app to develop FOLDER ACTIONS workflow nodes on folders is very stable and very responsive compared to the legacy method.
We've converted all our workflow using FOLDER ACTION applescripts to using this method with 100% success.
Post your results for others to see.
Warwick
Hong Kong