I’ve modified the built-in “add - new item alert.scpt” so that when it detects new files within a folder, it will move them to an external volume. If denied enough times that the total folder size reaches >20GB, it will point that out in a dialog preceding the move. However, this is my first folder action, and it doesn’t seem to have any effect when i add files to the folder that i’ve attached this action to.
Help?
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
-- 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
--find out if the folder has reached its size limit
set folder_size to (info for this_folder)
if the folder_size is greater than 2.0E+7 then
--create the alert string for folder limit
set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text
if the item_count is greater than 1 then
set alert_message to alert_message & "The new items added to " & «data utxt201C» & the folder_name & «data utxt201D» & " have increased the size of the folder to more than 20GB."
else
set alert_message to alert_message & "The new item added to " & «data utxt201C» & the folder_name & «data utxt201D» & " has increased the size of the folder to more than 20GB."
end if
set the alert_message to (the alert_message & return & return & "All items in this folder will be moved to your external drive.")
(*Here i intend to define the property added_items as all of the items in the folder, so that at the end of the script when Finder moves added_items, it would move everything in the folder.*)
--create the alert string for any new file(s)
else
set alert_message to ("Folder Actions Alert:" & 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 items have been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "." & return & return & "These items will be moved to your external drive."
else
set alert_message to alert_message & "One new item has been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "." & return & return & "This item will be moved to your external drive."
end if
end if
display dialog the alert_message buttons {"Cancel", "Ok"} default button 2 with icon 2 giving up after dialog_timeout
set the user_choice to the button returned of the result
if user_choice is "Ok" then
tell application "Finder"
move added_items to folder "/Volumes/Movies/iMovie Events"
end tell
end if
end try
end adding folder items to
Operating System: Mac OS X (10.5)