Automator Applescript – Use 1 Ask For Finder Item Selection for two different Actions

applescriptautomator

I'm working on an Automator Application where the bit I'm up to has a finder selection window open within the App – Telestream Switch.

My Next steps would be:

1 Ask For Finder Item
2 Copy Path Name
3 Return to Telestream Switch App – cmd shift G and paste path name and enter – So that the file is selected.
4 Refer back to point 1 so that the finder item is selected again.
5 Run the following apple script to copy only the item name.

on run {input, parameters}

set fileName to first item of input

tell application "System Events" to ¬
    tell disk item (fileName as text) to ¬
        set {theName, theExtension} to ¬
            {name, name extension}

if theExtension is not "" then
    set theName to ¬
        text 1 thru -((count theExtension) + 2) ¬
            of theName
    set the clipboard to theName
else
    set the clipboard to theName
end if

return input

end run

Would this be possible?

Thanks

Best Answer

To refer back to the value of a previous action, you can use the Set Value of Variable action and the Get Value of Variable action as appropriate, e.g.:

  • Ask for Finder Items action
  • Set Value of Variable action
  • Some other action.
  • Some other action.
  • Get Value of Variable action
  • Run AppleScript action
  • Some other action.

You should also check [√] Ignore this action's input in the Options section of the Set/Get Value of Variable action as appropriate so its action is logically disconnected from the next action.

In the example Automator workflow below, there would be other actions between the Set Value of Variable action and the Get Value of Variable action as wanted.

Note: If the Run AppleScript action is the last action in the workflow, then you do not need to include the return input line of code.

enter image description here