I am trying to make a simple program that can be used for renaming pictures. I need to be able to specify all of the variables. It really shouldn’t be too complicated, but I can’t seem to make it work.
I do have the option (for the computer to help) in universal access checked on.
I want the picture to be named with a specified 3 digit photographer code and then the number of the picture directly after that. The format should be:
photographer code + (no space) picture number + (no space) file extension
I want the program to:
Promt me for the pictures that I want to change the name of (with multiple selection)
Ask me for a 3 digit photographer code
Ask me what number I would like the first picture to be
Calculate how many pictures I have
Rename the photos with the photographer code + x (+1 for each picture) + file extension (x being the number that the numbering starts at)
This is the code that I have so far:
tell application "Finder"
activate
set photoselection to choose file with prompt "Select files to rename:" with multiple selections allowed
set photographercode to display dialog "Enter the photographer code:" default answer "000"
count photoselection
set photocount to photoselection count
set startcount to display dialog "You have selected " & photocount & " pictures. What number would you like to the photo numbers to start at?" default answer "000"
set fileextension to display dialog "What file extension would you like to use?" default answer ".jpg"
(* set file name of photoselection to photographercode *)
display dialog photographercode
end tell
Mine is a little bloated so I’d love to see some other responses with better coding so I can improve my Applescript.
But – it works.
tell application "Finder"
activate
set photoselection to choose file with prompt "Select files to rename:" with multiple selections allowed
set photographercode to display dialog "Enter the photographer code:" default answer "000"
count photoselection
set photocount to photoselection count
set startcount to display dialog "You have selected " & photocount & " pictures. What number would you like to the photo numbers to start at?" default answer "000"
set fileextension to display dialog "What file extension would you like to use?" default answer ".jpg"
set currentcount to (text returned of startcount) as integer
repeat with currfile from 1 to photocount
if currentcount is less than 100 and currentcount is greater than 10 then
set text_counter to "0" & currentcount
else if currentcount is less than 10 then
set text_counter to "00" & currentcount
else
set text_counter to currentcount
end if
set final_filename to (text returned of photographercode) & text_counter & (text returned of fileextension)
set name of file (item currfile of photoselection) to final_filename
set currentcount to 1 + currentcount
end repeat
end tell
Hi,
There’s nothing wrong with Bdemers code but this is less bloated!
tell application "Finder"
activate
set photoselection to choose file with prompt "Select files to rename:" with multiple selections allowed
set photographercode to text returned of (display dialog "Enter the photographer code:" default answer "000")
set startcount to text returned of (display dialog "You have selected " & (count of (every item of photoselection)) & " pictures. What number would you like to the photo numbers to start at?" default answer "000")
set fileextension to text returned of (display dialog "What file extension would you like to use?" default answer ".jpg")
repeat with this_photo in photoselection
if (count of characters of startcount) is 1 then
set startcount to "00" & startcount
else if (count of characters of startcount) is 2 then
set startcount to "0" & startcount
end if
set name of this_photo to photographercode & startcount & fileextension
set startcount to (startcount as integer) + 1 as string
end repeat
end tell
And here’s another way to skin a cat. I personally prefer this method of zero padding an integer versus the if statements
tell application "Finder"
activate
set photoselection to choose file with prompt "Select files to rename:" with multiple selections allowed
set photographercode to text returned of (display dialog "Enter the photographer code:" default answer "000")
set startcount to text returned of (display dialog "You have selected " & (count of (every item of photoselection)) & " pictures. What number would you like to the photo numbers to start at?" default answer "000")
set fileextension to text returned of (display dialog "What file extension would you like to use?" default answer ".jpg")
repeat with this_photo in photoselection
set name of this_photo to photographercode & (text -3 thru -1 of ("000" & startcount)) & fileextension
set startcount to (startcount as integer) + 1 as string
end repeat
end tell