Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonathanpenn/4026232 to your computer and use it in GitHub Desktop.
Save jonathanpenn/4026232 to your computer and use it in GitHub Desktop.
Toggle Between Script and Editor Log Views in UIAutomation Instrument
(*
Running this script will cause Instruments to become active
and switch from the Script view (where you edit your UIAutomation script)
to the Editor Log view (where you see the logs of executing those scripts)
or vice versa.
*)
-- JW: This block only needs to be executed once, and can then be removed.
-- I don't know if leaving it in might cause a performance hit;
-- the comment (copied from UI Browser) makes it seem like not.
on enabledGUIScripting(switch)
-- Call this handler and pass 'true' in the switch parameter to enable GUI Scripting before your script executes any GUI Scripting commands, or pass 'false' to disable GUI Scripting. You need not test the 'UI elements enabled' setting before calling this handler, because authorization is required only if 'UI elements enabled' will be changed. Returns the final setting of 'UI elements enabled', even if unchanged.
tell application "System Events"
activate -- brings System Events authentication dialog to front
set UI elements enabled to switch
return UI elements enabled
end tell
end enabledGUIScripting
enabledGUIScripting(true)
tell application "Instruments" to activate
tell application "System Events"
tell process "Instruments"
-- Open Script/Editor Log menu
-- Trace and action identified by using UI Browser
tell splitter group 1 of splitter group 1 of window 1
set navMenu to static text 2 of list 1
set currentValue to navMenu's value
tell navMenu to perform action "AXShowMenu"
end tell
end tell
-- I couldn't figure out how to identify the menu item to directly press it
-- so we press it using keystrokes instead
-- From bottom, menu reads "Script", "Editor Log"
-- so press up once always, and a second time if we need to switch to "Editor Log"
key code 126
if (currentValue is "Script") then
key code 126
end if
-- press enter
key code 36
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment