Mission control: switch to desktop1 + show desktop

applescriptmission-control

I'm bored of pressing 2 key shortcuts

need to write a script that tells mission control the following:

  1. if not at desktop1, switch to desktop 1
  2. perform "show desktop" (windows will be hidden\displayed, depending on how they are now)

PS: where can i find info on taming Mission Control and Finder?

currently i use it like this:

tell application "System Events"
    key code 18 using {option down, command down} --current shortcut for "Switch to Desktop 1"
    key code 103 --current shortcut to "Show Desktop"
end tell

but there is no check for "i'm on desktop 1 already", and no toggle (show\hide windows)

Best Answer

The in-n-out cannot be avoided with applescript, to my knowledge.

tell application "System Events"

    do shell script "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"
    delay 0.5
    tell process "Dock" to tell group 1 to tell list 1 to tell button 1 to click
    delay 0.5

    do shell script "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control 1"

end tell