2

I am trying to use automator to rename files based on the folder I select as the input. I want to take the folder name and if 1 of 4 phrases are found in the folder name, 1 of 4 variables would be used. I don't know applescript but I feel this is the way to go base on other languages I know.

Can anyone convert the following concept?

if file name contains "USA" then

var = "US"

elseif file name contains "CAN_FR" then

var = "CAFR"

elseif file name contains "CAN_EN" then

var = "CAEN"

end

Much appreciation to anyone that can help.

1 Answer 1

2

Try:

on run {input, parameters}

    tell application "Finder" to set folderName to name of first item of input
    if folderName contains "USA" then
        set var to "US"
    else if folderName contains "CAN_FR" then
        set var to "CAFR"
    else if folderName contains "CAN_EN" then
        set var to "CAEN"
    else
        set var to "Not Found"
    end if

    -- insert your code here
    return var

end run
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect! Functions just the way I need it.
Option tweak needed: What would I need to add so the last else statement would bring a prompt up. I am thinking like how the ask for text option works in automator. The prompt would say "Please manually define variable" and have one input line to type in. I found a situation where this might be needed. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.