Hello.
I see that you managed to get hold of a copy before I removed it.
Well, here is if not the real deal, a better one, as it lets you choose to rename the end of the name, or change name extention. Suffix is meant for the end of the name…
I’ve called it name - changer, since it lets you add to the front or end of the name, and only change the last suffix.
-it seems to me that nothing gets put into the name extension part of a filename in finder, but I have taken measures for it to be filled, when display file extension is false. (Or whatever the proper name of that property is.)
I have tested this script when the property extension hidden of a file is false, I haven’t tested it when extension hidden is true.
I’ll do that tomorrow, or late this evening, and come back with any changes. ( and some further “polishing”/decoration).
property scripttitle : "Finder Name Changer"
-- Upgraded to Mavericks 2013.11.8
main()
on main()
set ctr to 0
tell application id "MACS"
try
set the source_folder to (folder of the front window) as alias
on error -- no open folder windows
set the source_folder to path to desktop folder as alias
return
end try
set the prefix_or_suffix to ""
repeat
set {button_pressed, prefix_or_suffix} to ¬
{button returned, text returned} of ¬
(display dialog ¬
"Enter the prefix or suffix to use:" default answer the prefix_or_suffix ¬
buttons {"Cancel", "Prefix", "Suffix"} ¬
cancel button 1 default button 3 with icon note with title my scripttitle)
if button_pressed is "Suffix" and prefix_or_suffix is not "" then
set button_pressed to button returned of (display dialog ¬
"Do you want to change the end of the filename or the name extension?" buttons ¬
{"Cancel", "Suffix", "Extension"} cancel button 1 default button 3 ¬
with icon note with title my scripttitle)
end if
if the prefix_or_suffix is not "" then exit repeat
end repeat
script o
property item_list : {}
end script
set o's item_list to list folder source_folder without invisibles
set source_folder to source_folder as string
tell application id "MACS"
repeat with i from 1 to (length of o's item_list)
set this_item to item i of o's item_list
set this_item to (source_folder & this_item) as alias
tell (get properties of this_item)
set current_name to name of it
if class of it is not folder and ¬
class of it is not alias then
if the button_pressed is "Prefix" then
set new_file_name to prefix_or_suffix & current_name
else
set sl to length of its name extension
if sl > 0 then
set current_ext to its name extension
set current_name to text 1 thru (-1 * (sl + 2)) of current_name
else
tell me to set sl to (offset of "." in ((reverse of (characters of current_name)) as text))
if sl > 0 then
set current_ext to text -(sl - 1) thru -1 of current_name
set current_name to text 1 thru (-1 * (sl + 1)) of current_name
end if
end if
if the button_pressed is "Extension" then
set the new_file_name to current_name & "." & prefix_or_suffix
else -- "Suffix"
if sl > 0 then
set the new_file_name to current_name & prefix_or_suffix & "." & current_ext
else
set new_file_name to current_name & prefix_or_suffix
end if
end if
end if
try
local tmpctr
set tmpctr to (my set_item_name(this_item, new_file_name))
set ctr to ctr + tmpctr
on error
if ctr > 0 then
local nm
set nm to name of it
tell me to display notification "Renamed " & ctr & ¬
" Files before User Aborted Renaming " & nm with title my scripttitle
else
tell me to display notification "User Aborted. " with title my scripttitle
end if
error number -128
end try
end if
end tell
end repeat
display notification "Renamed " & ctr & " files. " with title my scripttitle
end tell
end tell
beep 2
end main
on set_item_name(this_item, new_item_name)
local ret_val -- 1 if we renamed the file, 0 if not, "for the record".
set ret_val to 0
tell application id "MACS"
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
set ret_val to 1
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
set {button_pressed, new_item_name} ¬
to {button returned, text returned} of ¬
(display dialog the error_message default answer new_item_name ¬
buttons {"Cancel", "Skip", "OK"} cancel button 1 default button 3 ¬
with icon caution with title my scripttitle)
if the button_pressed is not "Skip" then ¬
set ret_val to (my set_item_name(this_item, new_item_name))
end try
else --the name already exists
beep
set {button_pressed, new_item_name} ¬
to {button returned, text returned} of ¬
(display dialog ¬
"This name is already taken, please rename." default answer new_item_name ¬
buttons {"Cancel", "Skip", "OK"} ¬
cancel button 1 default button 3 with icon caution with title my scripttitle)
if the button_pressed is not "Skip" then ¬
set ret_val to (my set_item_name(this_item, new_item_name))
end if
end tell
return ret_val
end set_item_name