5

I am trying to pass a variable that has been set in Automator to an AppleScript within Automator. My Automator workflow is as follows:

Ask for Finder Items (only allowing folder type)

Set Value of Variable (variable set to "chosenfolder")

Get Value of Variable (chosenfolder)

Run AppleScript

property odd : true -- set to false to get odd numbers

on run {input, parameters}

set thefolder to (input as text)

set TheNumber to (odd as integer)
tell application "Finder"
    set FileList to every file of thefolder
    repeat with oneFile in FileList
        set Ex to name extension of oneFile
        set NameString to text -4 thru -1 of ("000" & TheNumber) & "." & Ex
        set name of oneFile to NameString
        set TheNumber to TheNumber + 2
    end repeat
end tell

return input
end run

This returns the error:

Can’t get every file of "Macintosh SSD:Users:etc....

Does anyone have any suggestions as to why the chosen folder in automator cannot be accepted in the AppleScript?

Note: I understand that I can just use "choose folder" in the AppleScript instead of using the Automator workflow items, but I truncated my actual workflow just to show this portion. The variable is needed elsewhere in the Automator workflow in addition to passing it to the AppleScript.

1 Answer 1

5

When using on run {input, parameters}, input is a list, and as such you need to change the following line of your code:

set thefolder to (input as text)

To:

set thefolder to (item 1 of input)

That will fix the Can’t get every file of ... error.

Also, while you didn't state the complete settings of the Get Value of Variable action, I'll assume that under Options, you have checked the [√] Ignore this action's input checkbox to unlink it from the preceding Set Value of Variable action. Otherwise, it passes the variable twice to the Run AppleScript action! That is, in this example workflow you've presented.

2
  • Would your answ r work here, too? apple.stackexchange.com/questions/146988/…
    – bmike
    Jul 26, 2017 at 0:22
  • @bmike, Without testing, I can't say as I've not had to need to run AppleScript and or Automator on a remote machine, and I cannot test it until tomorrow. That thread is going on 3 years old, so I think it's safe to wait till tomorrow to find out. Jul 26, 2017 at 0:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .