Reputation: 182
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
Upvotes: 0
Views: 219
Reputation: 1878
# 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"))
Another (simple) example for testing:
set process_bid to "com.google.Chrome"
run script ("tell application id \"" & process_bid & "\" to minimized of window 1")
Upvotes: 0
Reputation: 285260
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.
Upvotes: 0