15 January 12 / day 14 / 0 contributions

How to rename files from input in an Automator Workflow

Working with Hari’s little website can be slow some times with having to manually resize, rename and upload each file individually. So I decided the best route to take would be an Automator Workflow, nice and easy, so I thought.

Well, it turns out Automators default ‘Rename Files’ Action cannot accept a variable as an option to rename a file (EH?), I then went on the hunt for an alternative rename Action …. and failed. All the options gave me the same error.

In comes Applescript, a slightly less pretty option but it worked.

The solution I found was here  but I tweaked it ever so slightly so it worked to my liking, here is what I got.


on run {input, parameters}

	-- here the input is a reference to the file passed from the previous action
	set input to item 1 of input
	set defaultName to makeNewName()
	display dialog "Rename File To:" default answer defaultName buttons {"Rename", "Cancel"} default button "Rename" with icon note
	set newName to text returned of the result
	tell application "Finder"
		set ext to name extension of input
		set name of input to newName & "." & ext
	end tell
	return input
end run

to makeNewName()
	set root to "New Picture"
	set {year:y, month:m, day:d, time:t} to current date
	return root & " " & y & "-" & m * 1 & "-" & d & "_" & t
end makeNewName

No comments yet, be the first!

Leave a comment

Name (required)

Mail (required)

Website

Text