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


Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...