Created
August 6, 2018 22:45
-
-
Save bumper314/32db2a3bb5d5dc4d252b047c1c6ac32e to your computer and use it in GitHub Desktop.
Fix for finding the right "front most window" in an app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "System Events" | |
set myFrontMost to name of first item of (processes whose frontmost is true) | |
tell application process myFrontMost | |
-- The trick here is that you can't rely on "window 1" to be the one you're after, | |
-- So let's filter the UI elements list by subroles. | |
-- Emacs return a a total bogus AXTextField:AXStandardWindow, but we can stil work with it | |
set theWindows to (every UI element whose subrole is "AXStandardWindow") | |
-- For Activity Monitor (others?) | |
if theWindows is {} then set theWindows to (every UI element whose subrole is "AXDialog") | |
if theWindows is {} then | |
beep | |
return | |
end if | |
set theWindow to (first item of theWindows) | |
tell theWindow | |
set position to {0, 0} | |
set size to {800, 600} | |
end tell | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment