Automating Date

Discussion in 'Mac Apps and Mac App Store' started by phaedo5, Jul 8, 2009.

  1. phaedo5 macrumors newbie

    Jan 13, 2009
    I want to use Automator to insert a date in front of a file name. However, the date options for Finder in Automator are limited.

    I want this:

    To be this:

    They have options for doing something close to this, but I need it exactly as I I have it with periods as separators and two digit day and month.

    Is there anything I can do to make that happen in Automator?

    I know I can use something like A Better Finder Rename - but that costs I believe.
  2. mysterytramp macrumors 65816


    Jul 17, 2008
    It doesn't appear that Automator can do exactly what you want. Here's an Applescript that I believe will:

    on twodigits(num) -- turns "7/8/9" to '07/08/09"
    	if num > 9 then
    		return (num as string)
    		return "0" & (num as string)
    	end if
    end twodigits
    on datePeriods() -- fetches date string
    	set theYear to the year of the (current date) as string
    	set theMonth to my twodigits((the month of the (current date)) as integer)
    	set theDay to my twodigits(the (the day of the (current date)) as integer)
    	return theYear & "." & theMonth & "." & theDay
    end datePeriods
    on rename(anAlias) -- renames the file
    	tell application "Finder"
    		set theFileName to (the displayed name of anAlias)
    		set newFileString to my datePeriods() & "_" & theFileName
    			set the name of anAlias to newFileString
    		on error
    			display dialog "Couldn't rename " & theFileName
    		end try
    	end tell
    end rename
    on open fileNames -- these files have been dropped on droplet
    	repeat with theFileAlias in fileNames
    	end repeat
    end open
    on run -- this runs if you doubleclick on file
    	set theFileAlias to (choose file)
    end run
    Open script editor, paste this in the window and save it as an application.

    It creates a droplet that will let you drop files onto it, and rename those files. The "on run" handler lets you double click on the icon and you'll get a Finder open window to select a file.

    This worked on my machine. Holler if you have any problems.

    BTW, I haven't been able to test the error handler. If you see it in action, write back on whether it works as its supposed to.

  3. miles01110 macrumors Core


    Jul 24, 2006
    The Ivory Tower (I'm not coming down)
    Just use Name Mangler. It is the best file renaming utility I've found.

Share This Page