0

I am on Big Sur. My workflow involves like 10 static spaces that I access with CMD+NUM key shortcuts (not CTRL-NUM you can turn on in Sys Pref's Keyboard Shortcut section). Often I am just switching back and forth between two spaces, and would like to be able to toggle between the previous two spaces.

In Snow Leopard there was a 'double-tab-jump-back' key you could turn on with a 'defaults' terminal command (https://www.cultofmac.com/133205/use-a-secret-gesture-to-switch-to-the-previous-space-os-x-tips/). This is gone now:

$ defaults find double-tap-jump-back 
2021-08-05 10:35:11.617 defaults[5047:253260] No domain, key, nor value containing 'double-tap-jump-back'

Ideally, I would bind CMD+` (I never use it to switch between app windows) to function exactly like CMD+TAB's app switcher but it would be for spaces. This will almost certainly never happen.

So instead I'd just like to figure out a way to switch to the previous space. This would probably involve multiple small applescripts. The main script would save the current space before jumping to the previous one upon a CMD+` keypress. Then I would need 10 other scripts that save the current space before jumping using my CMD+NUM shortcuts. If I switched between spaces using trackpad gestures, then the previous space would not be kept current, but I don't use the trackpad often enough for this corner case to be addressed.

Unfortunately I am just returning to MacOS from a GNOME-based linux desktop and am not very familiar with applescript. Could someone help me draft a template main applescript and then a template for my CMD+NUM applescripts? I imagine this is the only way to accomplish this :)

Additional info:

I have a American English ANSI keyboard on m1 macbook air. I only use the single, built-in monitor and keyboard on this device. I never use full screen apps in their own spaces because I can't switch to them directly. Here are my settings (I don't change keybinds in System Preferences and instead use BetterTouchTool to bind the "Switch to Desktop X" and "Move Window to Desktop X" functions):

enter image description here enter image description here enter image description here

  • Spaces changed dramatically at Lion & really was never as good since. There's no way to get back those long-gone moves, I'm afraid. Spaces/Mission Control never did get an Applescript Dictionary & has been pretty intransigent ever since. We have one user on here who is a bit of a whiz on Applescript, though, so I'm not going to put this in as an answer. – Tetsujin Aug 05 '21 at 15:23
  • Hmm… a late thought. You could maybe just do the opposite of this - https://apple.stackexchange.com/questions/214348/how-to-prevent-mac-from-changing-the-order-of-desktops-spaces A truly horrible HUI function to my mind, but it might help a bit in this instance. You'd then just need [by default] Ctrl/ left or right arrow. – Tetsujin Aug 05 '21 at 16:20
  • There is a bit of missing information in this question, i.e, explicit settings in System Preferences > Mission Control and System Preferences > Keyboard > Shortcuts > Mission Control. Screenshots of each would be nice. Do you run any applications in Full Screen View that creates its own Desktop/Space that is not a part of the 10 already defined? Is this a single-display or a multiple-display environment? Type of Mac and keyboard? Language & Region settings? Without a solid overview of these settings I would not even attempt to offer an explicit answer. – user3439894 Aug 05 '21 at 16:33
  • That said, basic vanilla AppleScript, by itself without shelling out (using the do shell script command), does not have the vocabulary to accomplish the goal as Apple has not provided a Spaces API for AppleScript to access directly. There is a possibility using Hammerspoon with asm.undocumented.spaces, along with some AppleScript and or shell script to accomplish the goal. If you provide the missing info mentioned in my first comment I give this some serious thought. – user3439894 Aug 05 '21 at 16:33
  • 1
    @Tetsujin Ah I never considered allowing spaces to still reorder themselves by recency! It would be a very clean solution indeed. But I probably want to keep the mental organization and the quick nav that a 10 static Spaces approach provides. – courtyardz Aug 06 '21 at 14:43
  • @user3439894 I added the info. Thanks for taking the time to explain the limits of Applescript. If it is somehow easy for you to point me to functions involving Hammerspoon and the asm.undocumented.spaces I could read up and hack a Hammerspoon solution together -- if it is acceptable on AskDIfferent I would of course accept this info as an answer. Otherwise, it seems like I will just need to learn to "roll with" Apple's UI decisions. In this case, I will probably just have to rely on CMD-TAB to also switch me between recent spaces as it switches me between recent apps, and mash CMD-NUM o/w – courtyardz Aug 06 '21 at 14:53
  • RE: "(I don't change keybinds in System Preferences and instead use BetterTouchTool to bind the "Switch to Desktop X" and "Move Window to Desktop X" functions):" -- You never mentioned BetterTouchTool in your original question and not having BetterTouchTool I'm not sure if/how it may/may not complicate things. I'll have to install the trial and see. I'll look at it this weekend and report back. JSYK The may be an issue between BetterTouchTool and Hammerspoon as to which one is going to usurp the other from receiving the keystroke first. – user3439894 Aug 06 '21 at 15:01
  • I see. I don't mind moving the keyboard shortcuts to System Preferences from BetterTouchTool if there is a conflict between BetterTouchTool and Hammerspoon. You could just prototype something in Hammerspoon with the System Preferences CTRL-NUM "Switch to Desktop X" keybinds and then I could investigate if there is conflict myself after and report back. – courtyardz Aug 06 '21 at 17:29

0 Answers0