I’m trying to build a folder action that watches for folders of images to be added to it. When one arrives, the script should take the name of that folder and use it to modify the names of the image files within that folder
for example the path:
FAFolder/AddedFolderName/DSCN1001
would become
FAFolder/AddedFolderName/AddedFolderName1001
I had the script working with bare images, but I can’t get it to work when I modified it to work with folders of images.
Does anyone see what is wrong with my script below?
(the set_item_name procedure was borrowed from elsewhere)
Thank you.
azide
property text_to_trim : “DSCF” – the text to be removed from the begining of file names.
property itin_count : 0 --records how many times the script has run
on adding folder items to source_folder after receiving added_items
repeat with add_count from 1 to number of items in the added_items
set this_folder to item add_count of the added_items
set this_folderinfo to info for this_folder
if folder of this_folderinfo is true then
tell application "Finder"
set the folder_name to the name of this_folder -- record the name of this folder
set the this_folder to this_folder as alias
set folder_items to every item in this_folder
end tell
set the character_count to the number of characters of the text_to_trim
set this_folder to this_folder as string
repeat with i from 1 to number of items in the folder_items -- loop to process individual items
set this_item to item i of the folder_items
set this_info to info for this_item -- ***** the script seems to stop here *****
if folder of this_info is false then -- ignore folders for renaming
set the current_name to the name of this_info -- record it's name
if the current_name begins with the text_to_trim then -- ignore items with names that we are not interested in
-- crop out the text_to_remove
set the new_name to (characters (the character_count + 1) thru -1 of the current_name) as string
set the new_name to the folder_name & new_name -- create the new name
set_item_name(this_item, new_name) -- send the name to the renaming procedure
end if
end if
end repeat
end if
end repeat
end adding folder items to
on set_item_name(this_item, new_item_name)
– This procedure safley renames a Finder file/folder.
tell application “Finder”
–activate
set the parent_container_path to (the container of this_item) as text
if not (exists item (the parent_container_path & new_item_name)) then
try
set the name of this_item to new_item_name
on error the error_message number the error_number
if the error_number is -59 then
set the error_message to “This name contains improper characters, such as a colon (:).”
else --the suggested name is too long
set the error_message to error_message – “The name is more than 31 characters long.”
end if
–beep
tell me to display dialog the error_message default answer new_item_name buttons {“Skip”, “OK”} default button 2
copy the result as list to {new_item_name, button_pressed}
if the button_pressed is “Skip” then return 0
my set_item_name(this_item, new_item_name)
end try
else --the name already exists
–beep
tell me to display dialog “This name is already taken, please rename.” default answer new_item_name buttons {“Skip”, “OK”} default button 2
copy the result as list to {new_item_name, button_pressed}
if the button_pressed is “Skip” then return 0
my set_item_name(this_item, new_item_name)
end if
end tell
end set_item_name