Search code examples
applescript

AppleScript: cannot get property of window


I'm a newbie in AppleScript. I'm trying to write a short automator script that involves getting/setting window's miniaturized (or minimized for some apps apparently).

I'm totally lost at the point: Why the first attempt works but not the second one in the following codes?

# 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

Solution

  • The argument of tell application must be a literal (a constant) because the terminology of the application inside the tell block is evaluated at compile time.

    You could add a using terms from block, then the argument of tell application can be a variable. But this requires the argument of the block to be a constant.