AppleScript:无法获得 属性 的 window

AppleScript: cannot get property of window

我是 AppleScript 的新手。 我正在尝试编写一个简短的自动化程序脚本,其中涉及 getting/setting window 的 miniaturized(显然对于某些应用程序来说是 minimized)。

我完全迷失在这一点上:为什么在以下代码中第一次尝试有效但第二次尝试无效?

# Run this, and switch to Google Chrome, within 3 seconds
delay 3

# This works
tell application "/Applications/Google Chrome.app/"
    log (get minimized of first window)
end tell

tell application "System Events"
    set process_bid to get the bundle identifier of (first application process whose frontmost is true)
    set application_name to file of (application processes where bundle identifier is process_bid)
end tell
set front_app to POSIX path of (application_name as string)

# They're same
log (front_app = "/Applications/Google Chrome.app/")

# Then why is this not working?
tell application front_app
    log (get minimized of first window)
end tell

tell application 的参数必须是文字(常量),因为 tell 块中应用程序的术语在 编译 时计算.

你可以添加一个using terms from块,然后tell application的参数可以是一个变量。但这要求块的参数是一个常量。

# Run this, and switch to Google Chrome, within 3 seconds
delay 3

# This works
tell application id "com.google.Chrome" to log (get minimized of first window)

tell application "System Events"
    set process_bid to bundle identifier of (1st process whose frontmost is true)
end tell

# They're same
log (process_bid = "com.google.Chrome")

log (run script ("tell application id \"" & process_bid & "\" to minimized of window 1"))

另一个(简单的)测试示例:

set process_bid to "com.google.Chrome"

run script ("tell application id \"" & process_bid & "\" to minimized of window 1")