1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Rename photos in YYYYMM format

Discussion in 'Mac Programming' started by trustever, Apr 7, 2013.

  1. macrumors 6502

    #1
    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 Files:

  2. macrumors 6502

    #2
    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
     
  3. macrumors 6502

    #3
    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 Files:

  4. macrumors 6502a

    itickings

    #4
    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.
     
  5. macrumors member

    #5
    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/
     
  6. macrumors 6502

    #6
    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
     
  7. macrumors 6502a

    #7
    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 Files:

  8. macrumors 6502

    #8
    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.
     
  9. macrumors 6502

    #9
    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?
     
  10. kryten2, Apr 9, 2013
    Last edited: Apr 10, 2013

    macrumors 6502a

    #10
    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.
     
  11. macrumors 6502

    #11
    @ 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..
     

Share This Page