Search code examples
pythonapplescript

Python get variables from AppleScript program


I have recently been working with AppleScript, and was wondering if there is a way to get variables from AppleScript, and use them in Python. For example, say I have an AppleScript program called test.scpt and it has the following code in it:

set var1 to "hello"
set var2 to "hi"

In my python, I want to do something (like print) the values of those two variables:

print(var1)
print(var2)

I looked at answers like this, however most of the ones I found at years old. Is there a newer/better way to do this, and if not, what is the best way?

EDIT: I have also tried using osascript and os.system together, however I cannot store the output as a variable, as to the best of my knowledge osascript just runs the code, but cannot store variables.


Solution

  • Options: