Hi,
I am trying to add .jpeg to many jpeg files which show no suffix in their filenames.
The reason is that I want to burn them into a CD that must be readable by Windows XP.
All I know about droplets is that they must begin with:
on open fileList
repeat with thisFile in fileList
and end with:
end repeat
end open
But what should I write in between?
Thank you for a little help.
I use a Mac mini running Tiger
Incidentally, I tried to use a Finder script that comes with Tiger, called “Add to file names” but when I type .jpeg and click on Suffix, it goes away. Anyway a droplet would be better.
I have tried to write a file re-naming script in the past and it is actually pretty complicated. How do you handle files that already have an extension? What if the new file name already exists in the folder, etc…
In case you don’t get an answer from someone else here, there is a simple freeware utility I use called “R-Name”. Go to VersionTracker.com and search for it in OSX. It’s perfect for what you are doing.
on open item_list
set the prefix_or_suffix to ""
repeat
display dialog "Enter the prefix or suffix to use:" default answer the prefix_or_suffix buttons {"Cancel", "Prefix", "Suffix"}
copy the result as list to {the prefix_or_suffix, the button_pressed}
if the prefix_or_suffix is not "" then exit repeat
end repeat
repeat with i from 1 to number of items in the item_list
set this_item to item i of the item_list
set this_info to info for this_item
set the current_name to the name of this_info
if folder of this_info is false and ¬
alias of this_info is false then
if the button_pressed is "Prefix" then
set the new_file_name to the (the prefix_or_suffix & the current_name) as string
else
set the new_file_name to the (the current_name & the prefix_or_suffix) as string
end if
my set_item_name(this_item, the new_file_name)
end if
end repeat
beep 2
end open
on set_item_name(this_item, new_item_name)
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 {"Cancel", "Skip", "OK"} default button 3
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 {"Cancel", "Skip", "OK"} default button 3
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
Thank you for the script, (which I discoverd by chance as I had not been notified by e-mail that my post had a feedback)
Unfortunately, after copy-pasting the script in the Script Editor (who formatted it nicely), I pressed on the run button…and nothing happened. Not even a result window or an error notice. Any ides of what happened?
Since Vincent’s script has (or, more accurately is) an open handler, Maurice, it’s intended to be saved as an application and used as a droplet. You can also get it to respond to clicks by adding, below the rest of the script, a statement like this: