0

Automator automatically stores results from Applescript execution, but I can' t get them inside a Shell script executed right after. I' ve trid the $@, $1, $2 variable names but i only get an empty field when running even the simplest

echo $@

Here is the Applescript code:

set dialogResult to display dialog ¬
"Inserisci i valori numerici:" default answer ¬
"0,0,0,0" with title ¬
"Input 4 Valori" buttons {"Annulla", "OK"} ¬
default button "OK"

set inputText to text returned of dialogResult

-- Divide i valori separati da virgola
set AppleScript's text item delimiters to ","
set inputList to text items of inputText
set AppleScript's text item delimiters to ""

if (count of inputList) is not 4 then
    display dialog "Devi inserire esattamente 4 valori separati da virgola." buttons {"OK"} default button "OK"
    return
end if

-- Assegna nomi ai valori
set valore1 to item 1 of inputList
set valore2 to item 2 of inputList
set valore3 to item 3 of inputList
set valore4 to item 4 of inputList

-- Verifica che siano numerici
try
    set valore1 to valore1 as number
    set valore2 to valore2 as number
    set valore3 to valore3 as number
    set valore4 to valore4 as number
    return {valore1, valore2, valore3, valore4}
on error
    return {valore1, valore2, valore3, valore4}
end try
return {valore1, valore2, valore3, valore4}

which is followed by the

echo $@

These codes run inside an Automator Quick Action. I can see Automator previewing the results, but the shell script only prints empty fields. I am passing the results of the Applescript to the Shell script as "arguments". What am I doing wrong? Thank you in advance for your time!

3
  • What OS are you running? Note that the "Run Shell Script" action expects its input to be text. Commented Feb 23 at 0:01
  • I don't think you can assign a shell variable that way. You could just put your shell script inside a do shell script command that's inside the applescript. Commented Feb 23 at 4:17
  • 1
    @Mockman - a list of arguments can be returned by the "Run AppleScript" action, which can be indexed by a bash-like shell's special positional parameters, but in current OS versions the workflow will fail if the list items are numbers. Commented Feb 23 at 6:20

1 Answer 1

0

Try setting the bottom section to this:

-- Verifica che siano numerici
try
    set valore1 to valore1 as number
    set valore2 to valore2 as number
    set valore3 to valore3 as number
    set valore4 to valore4 as number
    set lip to {valore1, valore2, valore3, valore4}
on error
    set lip to {valore1, valore2, valore3, valore4}
end try
set text item delimiters to space
set lipt to lip as text

This should produce something like this: "0 0 0 0"

Then, for the run shell script action, change the pass input to as arguments.

1
  • Thank you - it works. But there a very important, very small detail I had missed as well: when we pile two Automator actions together, there must be the little arrow going into a little circle, meaning "Accept Input". I accidentally disabled input, so your code modification did not work at first. Anyway i can go on with my ork now, thank you all, and a lot! Cheers Commented Feb 23 at 8:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.