hiya,
…I’m trying to get a folder action working, but I think my scripting skills have been damaged from prolonged C++ usage!
…I’m basically trying to have a folder that is fed images over a network, but I only want to keep the latest 200 or so images…so, I tried to make a folder action that, on “adding folder items”, sorts the items by date and moves the oldest item to the trash: so far I just get “Error: -1728. Can’t get every item of alias “internal:Users:tigital:Desktop:test:”.”…
property max_files : 10 -- set the number of files for screensaver
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 this_folder
if the item_count is greater than max_files then
tell application "Finder"
--move oldest file to the trash
--sort this_folder by date and (move oldest to trash)
--On my machine, the sort puts the newest file first. If yours puts it last, change item 1 to item -1
set the oldest_file to the name of (info for (item 1 of (sort (get files of folder this_folder) by modification date)))
move oldest_file to trash
end tell
end if
on error the error_message number the error_number
set the error_text to "Error: " & the error_number & ". " & the error_message
-- the following line evokes the sub-routine to write the error into an error log created on the desktop
-- if the file "Script Error Log.txt" already exists, it will add one line to the log
my write_error_log(the error_text)
end try
end adding folder items to
on write_error_log(this_error)
set the error_log to ((path to desktop) as text) & "Script Error Log.txt"
try
open for access file the error_log with write permission
write (this_error & return) to file the error_log starting at eof
close access file the error_log
on error
try
close access file the error_log
end try
end try
end write_error_log
…any ideas?