Skip to content

Instantly share code, notes, and snippets.

@bumper314
Created August 6, 2018 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumper314/32db2a3bb5d5dc4d252b047c1c6ac32e to your computer and use it in GitHub Desktop.
Save bumper314/32db2a3bb5d5dc4d252b047c1c6ac32e to your computer and use it in GitHub Desktop.
Fix for finding the right "front most window" in an app
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