Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Automator variable in Applescript ?

enter image description here

So I have a an Applescript that displays a dialogue box and then automator sets a variable as the entry

Example . . . the input "AAAAAAA" the query variable would be "AAAAAAA"

i'm trying to figure out a way to call the variable while running my next applescript

i know how to do it with Python shell script by using sys.argv1 and stdin -> arguments

how can I achieve this with Applescript ?

I saw a similar post title but the answer did not address this question

like image 207
O.rka Avatar asked Oct 20 '22 15:10

O.rka


1 Answers

In the Run Applescript Actions.

You output using the return someVar.

....

return text_returned
    end run

And input to the Action is in the first argument normally name input

on run {input, parameters}
...

enter image description here

on run {input, parameters}

    display dialog "test" default answer "" buttons {"Cancel", "OK"} default button 1
    copy the result as list to {button_pressed, text_returned}

    return text_returned
end run

on run {input, parameters}

    set theQuery to input
end run

You would only need the set variable in this case if you wanted to reuse it.

In this example you could remove it and still get the same result.

If the argument is a list then you will need to use for example:

 on run {input, parameters}

        set theQuery to item 1 of input
    end run

Also note that if you get your display dialog code from the applescript contextual/menus scripts it will give you the line : copy the result as list to {button_pressed, text_returned}

To use it in Automator you need to swap around the :{button_pressed, text_returned} to {text_returned, button_pressed}

( Go figure..!)

like image 178
markhunte Avatar answered Oct 23 '22 10:10

markhunte