Skip to content

Instantly share code, notes, and snippets.

@ctanis
Created December 14, 2011 14:20
Show Gist options
  • Save ctanis/1476761 to your computer and use it in GitHub Desktop.
Save ctanis/1476761 to your computer and use it in GitHub Desktop.
task switcher to complement command tab (i have it on option-tab)
activate
on expose_app(appname)
-- figure out if the current frontmost application is full screen
-- set isFull to false
-- tell application "System Events"
-- set firstProc to (name of first process whose frontmost is true)
-- try
-- tell process firstProc
-- set isFull to (get value of attribute "AXFullScreen" of window 1)
-- end tell
-- end try
-- end tell
tell application (appname)
activate
try
set visible of every window to true
end try
try
set index of first window to 0
end try
end tell
delay 0.1
set isfull to false
try
tell application "System Events" to tell (first process whose frontmost is true)
set isfull to (value of attribute "AXFullScreen" of window 1)
end tell
end try
if not isfull then
-- invoke Mission Controls "show current application windows"
do shell script "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control 2"
tell application "System Events"
-- highlight something (hit up twice)
delay 0.25
key code 126 -- up arrow
delay 0.1
key code 126 -- up arrow
-- used to just try to pick a window, but leaving expose up is nicer
-- -- delay 0.5
-- -- key code 36 -- enter
end tell
end if
end expose_app
-- get names of all applications with at least one visible window
tell application "System Events"
set allprocs to (name of every application process whose visible is true and name is not "switch-win")
end tell
set names to []
repeat with proc in allprocs
tell application proc
try
if windows is not {} then
set names to names & name
end if
on error
set names to names & name
end try
end tell
end repeat
-- have the user choose one
set applist to (choose from list names with title "switcher!" with prompt "switch to:")
-- profit
if (applist is not false) then
expose_app(item 1 of applist)
-- else
-- tell original
-- activate
-- end tell
--
end if
@ctanis
Copy link
Author

ctanis commented Dec 14, 2011

usage

I saved this as an application, and bound it to option-tab using Alfred

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment