1

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. – clemsam lang Dec 1 '18 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". – clemsam lang Dec 1 '18 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). – clemsam lang Dec 1 '18 at 11:34
3

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 . . . – clemsam lang Nov 20 '18 at 10:33
1

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. – Serg Juxtaposse Oct 24 '14 at 13:13

You must log in to answer this question.

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