Hi
I want a folder action script that opens files which are put in a particular folder, after prompting with a list of the files in a display dialog and going ahead if no user action for 30 seconds.
I have done the following:
on adding folder items to this_folder after receiving these_items
display dialog "to test" default button "OK" giving up after 5
set ddBlock to ""
repeat with i from 1 to count (these_items)
set ddBlock to ddBlock & return & (name of item i of these_items) as string
end repeat
display dialog "File(s) to be opened:" & ddBlock default button "OK" giving up after 30
tell application "Finder" to open these_items
end adding folder items to
However, it never gets to the second display dialog and never opens files. I have not been able to figure out why as the first “test” display dialog always appears so the folder action script is being run when file(s) are added.
Help! What gives?
Model: PowerMac
AppleScript: Latest
Browser: Safari
Operating System: Mac OS X (10.4)
Hi, kiwilegal.
You’re trying to get the names of the items without using the Finder or ‘info for’. As a result, the script’s erroring and failing to complete. Unfortunately, script errors are mostly “silent” when running in OS X, unless you enclose the code in a ‘try’ block and use the ‘on error’ section to display a dialog with the error message.
try
-- Code here.
on error errMsg
display dialog errMsg
end try
Thanks for this. In desperation, I had put the whole script inside a “Finder” tell but that did not solve the problem. However, your comment put me back on track.
Script which now works is:
on adding folder items to this_folder after receiving these_items
try
set ddBlock to ""
repeat with i from 1 to count (these_items)
tell application "Finder" to set nme to (i as string) & ". " & name of item i of these_items
set ddBlock to ddBlock & return & nme as string
end repeat
on error errMsg
display dialog errMsg
end try
display dialog ddBlock default button "OK" with title "FILES TO OPEN IN 60 SECONDS" giving up after 60
tell application "Finder" to open these_items
end adding folder items to