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

phaedo5

macrumors newbie
Original poster
Jan 13, 2009
8
0
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:
filename.ext

To be this:
2009.07.08_filename.ext

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.
 
It doesn't appear that Automator can do exactly what you want. Here's an Applescript that I believe will:

Code:
on twodigits(num) -- turns "7/8/9" to '07/08/09"
	if num > 9 then
		return (num as string)
	else
		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
		try
			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
		
		rename(theFileAlias)
		
	end repeat
	
end open


on run -- this runs if you doubleclick on file
	set theFileAlias to (choose file)
	rename(theFileAlias)
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.

mt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.