Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 7, 2013, 12:55 PM   #1
trustever
macrumors 6502
 
Join Date: Jan 2013
Rename photos in YYYYMM format

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
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-04-07 at 18.53.57.png
Views:	56
Size:	192.4 KB
ID:	406653  
trustever is offline   0 Reply With Quote
Old Apr 7, 2013, 01:25 PM   #2
Red Menace
macrumors 6502
 
Join Date: May 2011
Location: Littleton, 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
__________________
MacBook Pro / OS X Mavericks (10.9.5) / Xcode 6.0.1 / RubyMotion FTW
Red Menace is offline   0 Reply With Quote
Old Apr 7, 2013, 03:18 PM   #3
trustever
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
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..
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-04-07 at 21.16.34.png
Views:	27
Size:	211.3 KB
ID:	406687  
trustever is offline   0 Reply With Quote
Old Apr 7, 2013, 03:39 PM   #4
itickings
macrumors 6502a
 
itickings's Avatar
 
Join Date: Apr 2007
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.
__________________
Rawr!
itickings is offline   0 Reply With Quote
Old Apr 7, 2013, 05:43 PM   #5
neier
macrumors member
 
Join Date: Apr 2003
Location: Japan
exiftool

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/
neier is offline   1 Reply With Quote
Old Apr 7, 2013, 07:28 PM   #6
Red Menace
macrumors 6502
 
Join Date: May 2011
Location: Littleton, Colorado, USA
Quote:
...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
__________________
MacBook Pro / OS X Mavericks (10.9.5) / Xcode 6.0.1 / RubyMotion FTW
Red Menace is offline   0 Reply With Quote
Old Apr 8, 2013, 09:17 AM   #7
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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.
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2013-04-08 at 15.59.50.png
Views:	18
Size:	223.8 KB
ID:	406843   Click image for larger version

Name:	Screen Shot.png
Views:	20
Size:	207.5 KB
ID:	406844  
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Apr 8, 2013, 01:49 PM   #8
Red Menace
macrumors 6502
 
Join Date: May 2011
Location: Littleton, 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.
__________________
MacBook Pro / OS X Mavericks (10.9.5) / Xcode 6.0.1 / RubyMotion FTW
Red Menace is offline   0 Reply With Quote
Old Apr 9, 2013, 01:46 PM   #9
trustever
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
Quote:
Originally Posted by kryten2 View Post
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?
trustever is offline   0 Reply With Quote
Old Apr 9, 2013, 03:48 PM   #10
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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.
__________________
Space Corps Directive 34124

Last edited by kryten2; Apr 10, 2013 at 06:26 PM. Reason: Added note
kryten2 is offline   0 Reply With Quote
Old Apr 10, 2013, 03:34 AM   #11
trustever
Thread Starter
macrumors 6502
 
Join Date: Jan 2013
@ 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..
trustever is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Second internal Advanced Format Drive - Won't Initialize / Format 1Tb 7K1000 OSX 10.9 ShaggyDog MacBook Pro 6 Sep 3, 2014 02:45 PM
How do you rename OS on rEFIt? Apple Noob Windows, Linux & Others on the Mac 0 Mar 10, 2013 05:04 PM
Rename dcim? ivnj iOS 5 and earlier 1 Feb 13, 2013 11:46 PM
How do I rename photos? DarrenUK Mac Basics and Help 6 Dec 30, 2012 05:31 PM

Forum Jump

All times are GMT -5. The time now is 03:06 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC