【发布时间】:2021-12-14 20:08:06
【问题描述】:
如何在tell应用程序中从我的python脚本调用一个全局变量?这是可能去向的示例。假设我想从全局 python 变量中更改 AppleScript 外部的所有“前窗”。这怎么可能发生?
import subprocess
def get_window_title():
cmd = """
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
"""
result = subprocess.run(['osascript', '-e', cmd], capture_output=True)
return result.stdout
print(get_window_title())
【问题讨论】:
标签: python applescript message imessage osascript