Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

trustever

macrumors 6502
Original poster
Jan 14, 2013
290
0
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
 

Attachments

  • Screen Shot 2013-04-07 at 18.53.57.png
    Screen Shot 2013-04-07 at 18.53.57.png
    192.4 KB · Views: 179

Red Menace

macrumors 6502a
May 29, 2011
578
226
Colorado, USA
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:

Code:
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

macrumors 6502
Original poster
Jan 14, 2013
290
0
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..
 

Attachments

  • Screen Shot 2013-04-07 at 21.16.34.png
    Screen Shot 2013-04-07 at 21.16.34.png
    211.3 KB · Views: 135

itickings

macrumors 6502a
Apr 14, 2007
947
185
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. Makes renaming very straightforward.
 

Red Menace

macrumors 6502a
May 29, 2011
578
226
Colorado, USA
...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):

Code:
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

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
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.
 

Attachments

  • Screen shot 2013-04-08 at 15.59.50.png
    Screen shot 2013-04-08 at 15.59.50.png
    223.8 KB · Views: 128
  • Screen Shot.png
    Screen Shot.png
    207.5 KB · Views: 131

Red Menace

macrumors 6502a
May 29, 2011
578
226
Colorado, USA
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

macrumors 6502
Original poster
Jan 14, 2013
290
0
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

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
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 :

Code:
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.
 
Last edited:

trustever

macrumors 6502
Original poster
Jan 14, 2013
290
0
@ 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..
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.