Automator Renaming

Hello,

I am trying to create an automator action to rename a particular part of the folder name.

Example - I have a folder called: Project 001 - [Status]

The Status would have several options example,
On Going
Pending
Completed

How can do this? I would like the automator to select the folder, it will be presented with a dropdown of options. When the user selects the a particular option, the folder name would be changed.

To example, Project 001 - [On Going]

Thank you.

Hi BitCy.

It looks as if it would be quite clunky to do that using the Automator actions I can see. There’d have to be at least two "Run AppleScript"s in the workflow: one to provide the list for “Choose from List” and another to prepare the file name. If you need the process to be an Automator workflow, the easiest thing would be for it to consist of just one “Run AppleScript” action with a script which does the entire job:

on run {input, parameters}
	-- Get user input for the target folder and status text.
	set theFolder to (choose folder with prompt "Choose a project folder…")
	set textToInsert to (choose from list {"On Going", "Pending", "Completed"} with prompt "Select a status…")
	if (textToInsert is false) then error number -128 -- "Cancel" button clicked.
	set textToInsert to item 1 of textToInsert
	
	-- Get the folder's name.
	tell application "System Events" to set folderName to theFolder's name
	
	-- If the name already has a " - […]" suffix, get the part before that.
	if ((folderName ends with "]") and (folderName contains " - [")) then
		set folderName to text 1 thru ((offset of " - [" in folderName) - 1) of folderName
	end if
	-- Append a new suffix containing the selected status text.
	set newName to folderName & " - [" & textToInsert & "]"
	
	-- Rename the folder with the result.
	tell application "System Events" to set theFolder's name to newName
end run

Wow! Brilliant!

Thank you, Nigel Garvey!! Really appreciate it! :slight_smile: