Created
January 28, 2011 02:14
-
-
Save kch/799697 to your computer and use it in GitHub Desktop.
Test case for WTF is up with System Events getting the processes for Safari and WebKit
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
#!/bin/bash | |
function safari { open -a Safari; } | |
function webkit { open -a WebKit; } | |
function reset { | |
killall Safari 2>/dev/null | |
killall WebKit 2>/dev/null | |
} | |
function bring_front { | |
osascript -e "tell application \"$1\" to activate" | |
} | |
function get_name_of_frontmost_with_assignment { | |
echo -n "assigned: " | |
osascript -e 'tell application "System Events" to set _app to the first process whose frontmost is true | |
get the short name of _app' | |
} | |
function get_name_of_frontmost_directly { | |
echo -n "directly: " | |
osascript -e 'tell application "System Events" to get the short name of the first process whose frontmost is true' | |
} | |
echo "### with only safari running" | |
reset; safari | |
get_name_of_frontmost_directly | |
get_name_of_frontmost_with_assignment | |
sleep 2 | |
echo "### with only webkit running" | |
reset; webkit | |
get_name_of_frontmost_directly | |
get_name_of_frontmost_with_assignment | |
sleep 2 | |
echo "### with both running, safari started first, safari frontmost" | |
reset; safari; webkit | |
bring_front Safari | |
get_name_of_frontmost_directly | |
get_name_of_frontmost_with_assignment | |
echo "### with both running, safari started first, webkit frontmost" | |
bring_front WebKit | |
get_name_of_frontmost_directly | |
get_name_of_frontmost_with_assignment | |
sleep 2 | |
echo "### with both running, webkit started first, webkit frontmost" | |
reset; webkit; safari | |
bring_front WebKit | |
get_name_of_frontmost_directly | |
get_name_of_frontmost_with_assignment | |
echo "### with both running, webkit started first, safari frontmost" | |
bring_front Safari | |
get_name_of_frontmost_directly | |
get_name_of_frontmost_with_assignment | |
reset |
Output reformatted as a pretty table:
+----------------+-----------+----------+----------+
| Launch order | Frontmost | directly | assigned |
+----------------+-----------+----------+----------+
| Safari | | Safari | Safari |
| WebKit | | WebKit | WebKit |
| Safari, WebKit | Safari | Safari | Safari |
| Safari, WebKit | WebKit | WebKit | Safari * |
| WebKit, Safari | WebKit | WebKit | WebKit |
| WebKit, Safari | Safari | Safari | WebKit * |
+----------------+-----------+----------+----------+
*
indicates incorrect results.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: