Dynamically loading an Automator action based on a filename

applescriptautomator

I would like to create an Automator action that will load an external Automator action based on a portion of a filename, on folder drag.

For example:

Filename[Type1].xxx
Filename[Type2].xxx
Filename[Type3].xxx

Type 1 – 3 will run a specified automator tailored for that file. Is this at all possible?

Best Answer

Save the following script as an application. Copy and paste into Script Editor (not automator):

on open myItems
    set ds to {"file1", "file2", "file3"} # Enter identifiyers
    set scriptlocation to {"dothis.app", "imeanthis.app", "PleaseUpvoteMy.app} # Enter scripts location as POSIX path, respectivly
    repeat with myItem in myItems
        tell application "Finder"
            set theName to the name of (myItems as alias)
        end tell
        set rptvly to getIndex of theName of ds
        do shell script "open " & the quoted form of rptvly
    end repeat
end open




to getIndex of i from l
    repeat with n from 1 to count l
        if (i as string) contains ((l's item n) as string) then return n
    end repeat
    0
end getIndex

Comment any errors as I am on Mojave beta and having issue where I cannot run sccripts