Jump to content

Add any prefix string to the names of the selected files [action workflow]

Recommended Posts

My file management scheme requires me to add prefixes to the names of files, which are then picked up by Hazel and handled in various ways. My applescript skills are admittedly crude, but here is my workflow (driven by a file action) to prompt the user for a prefix string and then add that string to the names of all the selected files. Right now, the default prefix in the dialog box is "archive-" but that's easily changed from within the simple applescript.

The workflow is here: http://d.pr/f/bDxq

But if you just want a peek at my weak applescripting chops, here you go:

on alfred_script(q)
	set prefixValue to display dialog "Enter prefix string: " default answer "archive-"
	set AppleScript's text item delimiters to tab
	set fileList to every text item of q
	repeat with theFilename in fileList
		set theFile to POSIX file theFilename
		tell application "Finder"
			set fileAlias to theFile as alias
			set fileName to name of fileAlias
			set newFilename to (text returned of prefixValue & fileName)
			set name of file theFile to newFilename
		end tell
	end repeat
end alfred_script


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...