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)

  • How to you call your script: by shortcut or menu used item or how? … this influences reactions, too. . . . Anyway, on my Mac (i7-3740QM cpu) your above code only works if I add delays of 0.5 after each "press" . . . And: if in "show desktop" mode, any starting an app "closes" this mode. So, starting your code from menu 1st closes "show desktop" and toggles BACK to "show desktop". . . In my case a simple "F11" / "F11" toggles modes much easier once you are in your desired workspace. Dec 1, 2018 at 10:39
  • In regards to your last sentence's first part, others have wondered how to know on which desktop you are currently, see stackoverflow.com/questions/53132824/… "How to get the current workspace programmatically on macOS" wheretell application "System Events" to set BGpict1 to last text item of (picture of current desktop as text) is used to compare to a list. NOW, you could do this "demand" TWICE (>BGpict2), before and after key codes. If they are identical you are still in desktop 1. Do a simple "display dialog". Dec 1, 2018 at 10:56
  • The way such a query works: "get BGpict1" > do your key codes > "get BGpict2" > compare and tell user . . . will EACH TIME(!) "close show desktop". I think what you need is a "stationary" variable, implemented by writing a separate Stay-Open-AppleScript, that stores BGpict-information between calls of your script as "property". . . . Otherwise you might set a "constant" value in your script (=name of desktop 1 picture AND maybe a 2nd one for "desktop status") leave out the 1st "get BGpict1" and only "do your key codes" if you are NOT on desktop 1 (= if BGpict 2 doesn't equal your constant). Dec 1, 2018 at 11:34

2 Answers 2


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
  • Probably since OS 12 Sierra, certainly with OS 13.6 High Sierra, your "inline" tell-block does no longer work. Now it has to be: . . . tell process "Dock" to click UI element 1 of list 1 of group 2 of group 1 of group 1 . . . Nov 20, 2018 at 10:33
  • I have seen other cases where the "common wisdom" was a thing was not possible only to see folks find creative workarounds. E.g., some say pointing the Desktop folder/directory at another requires restarting Finder, which then requires closing and reopening all open Finder windows and dependent processes. When I tried it, it took 16 seconds. But an alternate method, used by Clarity to empty your Desktop or swap Desktop configurations, is to leave the actual folder in place and swap the contents. That does not require restarting Finder and does the job in under 2 seconds, which is acceptable.
    – August
    Mar 12, 2022 at 19:30

Did you consider using Keyboard Maestro?

Here you can see how I deal with this. I use it to change between screens, but is really easy to modify per your requests.

  • thank you very much! actually, i want to do it with applescripts. Oct 24, 2014 at 13:13
  • 2
    The "Here" link above (from 7 years ago) appears to be dead. Depending on which browser I use, I redirected to security apps, job listings, etc. --- Does anyone have an update?
    – August
    Sep 24, 2021 at 5:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .