PDA

View Full Version : Rename photos in YYYYMM format




trustever
Apr 7, 2013, 12:55 PM
DA,


I have used the automator script to rename a big bunch of photos in the format YYYYMMDD filename.xxx, automator does not give the option of changing the name in YYYYMM filename.xxx, do you have any suggestion of small script to get to YYYYMM filename.xxx?

Thanks and regards in advance



Red Menace
Apr 7, 2013, 01:25 PM
I was going to suggest dropping the Today's date variable into the Rename/Add Text action and edit the format, but that doesn't work either, so you can give the following Run AppleScript a try:

on run {input, parameters}
set output to {}
tell ((current date) as «class isot» as string) to set myDate to text 1 thru 4 & text 6 thru 7
tell application "Finder" to repeat with anItem in the input
set anItem to contents of anItem
set name of anItem to myDate & space & name of anItem
set end of output to anItem
end repeat
return output
end run

trustever
Apr 7, 2013, 03:18 PM
Hi Red Menace,


thanks for getting back to me, I have tried using your script but id does not work.
I am sure I am doing a rooky mistakes but was wondering what..

itickings
Apr 7, 2013, 03:39 PM
Just for clarification, where do you expect YYYYMM to come from?
The file's creation date? The file's last modification date? The current date? Somewhere else?

On the off chance you are more interested in changing file names than actually making a script, consider having a look at for example A Better Finder Rename (http://www.publicspace.net/ABetterFinderRename/). Makes renaming very straightforward.

neier
Apr 7, 2013, 05:43 PM
Since you are talking about pictures, if you are comfortable with the command line, this program uses the data stored by the camera (EXIF) to change the filename, etc. and you can make your own format.

http://www.sno.phy.queensu.ca/~phil/exiftool/

Red Menace
Apr 7, 2013, 07:28 PM
...I have tried using your script but it does not work.

This is why no one uses Automator that much - Apple just doesn't pay any attention to it at all. The Get Specified Finder Items action says it passes Finder Items to the next action, but it actually passes POSIX paths, which the Finder can't use. The following Run AppleScript action will convert the input to aliases, which the Finder knows about (System Events can also be used, but the terminology changes depending on if it is a POSIX path or an alias):

on run {input, parameters}
set output to {}
tell ((current date) as «class isot» as string) to set myDate to text 1 thru 4 & text 6 thru 7
tell application "Finder" to repeat with anItem in the input
set anItem to anItem as text
if anItem begins with "/" then set anItem to anItem as POSIX file
set anItem to anItem as alias
set name of anItem to myDate & space & name of anItem
set end of output to anItem
end repeat
return output
end run

kryten2
Apr 8, 2013, 09:17 AM
Red Menace's first posted Run Applescript runs just fine.

@trustever

Notice that in your attached tumbnail your Run Applescript does nothing but returning the input. The rest of the script is commented out.

Red Menace
Apr 8, 2013, 01:49 PM
Hmmm, hadn't even noticed that! My original script was tested using the Ask for Finder Items, but I had it fail using the Get Specified Finder Items action for the mentioned reason. Automator is still goofy, though.

trustever
Apr 9, 2013, 01:46 PM
Red Menace's first posted Run Applescript runs just fine.

@trustever

Notice that in your attached tumbnail your Run Applescript does nothing but returning the input. The rest of the script is commented out.

Mate thanks for pointing that out, the script did work but put the today's date where I wanted to put the creation date. Tried putting in the script creation date but it does not work. Any other suggestion?

kryten2
Apr 9, 2013, 03:48 PM
Yes current date in Applescript is today's date. Do you mean the creation date of the files you're inputting? If so try this :

on run {input, parameters}
set output to {}
--tell ((current date) as «class isot» as string) to set myDate to text 1 thru 4 & text 6 thru 7
tell application "Finder" to repeat with anItem in the input
set anItem to anItem as text
if anItem begins with "/" then set anItem to anItem as POSIX file
set anItem to anItem as alias
set creationDate to creation date of anItem
tell ((creationDate) as «class isot» as string) to set myDate to text 1 thru 4 & text 6 thru 7
set name of anItem to myDate & space & name of anItem
set end of output to anItem
end repeat
return output
end run

Note : The creation date property of a Finder item is the date on which the item was created. If you want the date the photo was taken your best option would be to use the exiftool like neier suggested.

trustever
Apr 10, 2013, 03:34 AM
@ Kryten2 thanks I will try it as soon as I get home, I am not really in favour of installing new apps when automator can somehow handle it..