Thursday, February 25, 2021

#1 2020-02-02 05:26:38 pm

BitCy
Member
Registered: 2020-01-12
Posts: 11

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.

Last edited by BitCy (2020-02-02 05:42:26 pm)

Offline

 

#2 2020-02-03 05:09:51 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5356

Re: Automator Renaming

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:

Applescript:

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


NG

Offline

 

#3 2020-02-03 07:50:39 pm

BitCy
Member
Registered: 2020-01-12
Posts: 11

Re: Automator Renaming

Wow! Brilliant!

Thank you, Nigel Garvey!! Really appreciate it! smile

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)