(* add - new item alert This Folder Action handler is triggered whenever items are added to the attached folder. The script will display an alert containing the number of items added and offering the user the option to reveal the added items in Finder. Copyright © 2002Ð2007 Apple Inc. You may incorporate this Apple sample code into your program(s) without restriction. This Apple sample code has been provided "AS IS" and the responsibility for its operation is yours. You are not permitted to redistribute this Apple sample code as "Apple sample code" after having made changes. If you're going to redistribute the code, we require that you make it clear that the code was descended from Apple sample code, but that you've made changes. *) property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer. on adding folder items to this_folder after receiving added_items try tell application "Finder" --get the name of the folder set the folder_name to the name of this_folder end tell -- display dialog "New Doc" buttons {"OK"} set the_ruby_command to quoted form of POSIX path of ((this_folder as Unicode text) & "auto_file.rb") set the_folder_quoted to quoted form of POSIX path of this_folder -- display dialog the_ruby_command buttons {"OK"} delay 20 set autofile_output to do shell script "cd " & the_folder_quoted & " ; " & the_ruby_command & " " & the_folder_quoted -- Wait about 5 seconds for the PDF to finish generating -- find out how many new items have been placed in the folder set the item_count to the number of items in the added_items --create the alert string set alert_message to ("New Document(s) added to " & return & the folder_name & 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 items have " else set alert_message to alert_message & "One new item has " end if set alert_message to alert_message & "been placed in folder " & Çdata utxt201CÈ & the folder_name & Çdata utxt201DÈ & "." *) set the alert_message to (the alert_message & return & autofile_output) display dialog the alert_message buttons {"Ok"} giving up after dialog_timeout on error m number n display dialog m set the_log to open for access "/tmp/ruby_auto_filer_folder_action.log" with write permission try write n & tab & m & return to the_log starting at eof close access the_log end try close access the_log end try end adding folder items to