Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!


Click here to return to the 'Use launchd to replace folder actions' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Use launchd to replace folder actions
Authored by: TheCrunge on Thu, Apr 24 2008 at 7:09AM PDT
The biggest problem I've found with using launch daemons is that you can't pass the name of the added item. Using folder actions, you can get the name and the path of each item added. For example:
on adding folder items to this_folder after receiving added_items
         repeat with the_item in added_items
                   set the_posix to POSIX path of the the_item
                   display dialog "The added item is " & the_item & " and is located at " & the_posix
         end repeat
end adding folder items to
Using launch daemons, there is no argument passed to your script providing the name or the path of the item. It makes it difficult to manipulate this new file without knowing it's name or path. Am I wrong?

[ Reply to This | # ]
Use launchd to replace folder actions
Authored by: Zeitkind on Thu, Apr 24 2008 at 1:16PM PDT
It simply depends on your needs. In my case, I know that there will be one to many tiff-files which need to be ocr'ed. It's very simple to get a list of files with AppleScript:
tell application "Finder"
set myFolder to alias "Volumename:path:to:folder:"
set myList to every file of myFolder as alias list
end tell
You then have an array with all the files as alias. With a repeat or while or whatever kind of loop you can process the files.

[ Reply to This | # ]
Use launchd to replace folder actions
Authored by: ceesaxp on Fri, May 2 2008 at 10:23PM PDT
Well, I suppose (have not tried) that launchd when calling whatever.sh would be passing it each item one-by-one (i.e. calling it several times if multiple items were added). In case of /bin/sh they will be known to shell script as $1, and then will be passed over to AppleScript. So, you should have all the same (or similar) info and control, no?

[ Reply to This | # ]