Sto cercando di incorporare un AppleScript in uno script Python. Non voglio salvare l'AppleScript come file e quindi caricarlo nel mio script Python. C'è un modo per inserire AppleScript come una stringa in Python e avere Python per eseguire l'AppleScript? Grazie mille.Come incorporare un AppleScript in uno script Python?
Ecco il mio script: import sottoprocesso import re import os
def get_window_title():
cmd = """osascript<<END
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
tell application frontApp
if the (count of windows) is not 0 then
set window_name to name of front window
end if
end tell
return window_name
END"""
p = subprocess.Popen(cmd, shell=True)
p.terminate()
return p
def get_class_name(input_str):
re_expression = re.compile(r"(\w+)\.java")
full_match = re_expression.search(input_str)
class_name = full_match.group(1)
return class_name
print get_window_title()
Per vostra informazione, c'è un piccolo modulo Python su PyPI che fare il trucco: http://pypi.python.org/pypi/python-applescript/0.1 – ohe