How to call Automator variable in Applescript ?
Asked Answered
A

1

7

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

Archaeozoic answered 27/1, 2014 at 21:18 Comment(0)
H
5

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..!)

Himes answered 1/2, 2014 at 0:29 Comment(1)
I think set {button_pressed, text_returned} to {button returned, text returned} of resultor copy {button returned, text returned} of result to {button_pressed, text_returned} is much better, because then you don't really have to rely on the order of the properties, which are really specified to be unordered. So,approach shown works everywhere.Iceland

© 2022 - 2024 — McMap. All rights reserved.