I have a Folder Action Script that I cobbled together a while back that monitors when a USB drive is attached, then looks for a shell script on that drive and runs it if I tell the Folder Action Script “Yes”. If I click “No” it closes out the dialog and all is well.
It still works at the heart of things, however now when I click “Yes” the dialog box stays visible until the shell script completes, whereas in the past it would disappear immediately after clicking “yes” or “No”.
Any help is greatly appreciated, and thanks in advance!
Code:
property dialog_timeout : 60
on adding folder items to this_folder after receiving added_items
set shFiles to {}
repeat with current_item in added_items
try
set end of shFiles to ((current_item as text) & ".Autosync.sh") as alias -- check if ".Autosync.sh" exists
end try
end repeat
if shFiles is not {} then
tell application "Finder" to set the folder_name to the name of this_folder
-- find out how many .Autosync.sh
set the item_count to count shFiles
--create the alert string
set alert_message to ("External Drive Attached" & return & return) as Unicode text
if the item_count is greater than 1 then
set alert_message to alert_message & (the item_count as text) & " new drives have "
else
set alert_message to alert_message & "One new drive has "
end if
set alert_message to alert_message & "been attached, in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "."
set the alert_message to (the alert_message & return & return & "Would you like to run Autosync?")
activate
display dialog the alert_message buttons {"Yes", "No"} default button 2 with icon 1 giving up after dialog_timeout
set the user_choice to the button returned of the result
if user_choice is "Yes" then
repeat with shFile in shFiles
try
do shell script quoted form of POSIX path of shFile
end try
end repeat
end if
end if
end adding folder items to