I am an avid user of the Mission Control Desktop Workspaces feature of Mac OS. But keeping track of which space I'm in, and even moreso what the previous space was, is frequently a problem.
There are some little tools on GitHub such as WhichSpace (currently at v0.3.2) which do things like put a little icon in the tool bar to tell you the number of the Desktop Workspace you're currently in. But it would be hugely more useful if a change of workspace could trigger an AppleScript script.
There are many various ways that the active desktop workspace can be changed manually. I can use the keyboard hotkeys Ctl+Left and Ctl+Right, swipe left or right, open Mission Control and pick a Desktop from the list that appears at the top of the screen, etc. And there are ways the desktop workspace gets changed without my direct decision. I click an application in the taskbar and instead of opening a new window, I get taken to the space that already has an open window. I use the new Chrome tab list (the down arrow at the upper right) and pick a tab and I have no idea what space that window is in, but I go there.
Is there some way in which, no matter what is causing me to change spaces, in or out of my control, a script or function could be called and be given parameters of the old and new space numbers, or at least the new space number?
I am looking for ways to replicate some of the functionality of CurrentKey Stats, which is no longer supported. In the latest versions of CKS, a feature can be turned on so that whenever the space was changed, by whatever means, an AppleScript script is called:
/Users/[username]/Library/Application Scripts/com.currentkey.stats/ck.scpt
and a function in that script is given a parameter of the identity of the new space. This turns out to be really useful.
That's what I'm trying to do, in a way that is not dependent on abandoned software. But doing anything along those lines seems to hinge on being able to be notified whenever any app or system process changes the current space and what that change is.
Does anyone know how to do that?
(The author of CurrentKey just became a father last week, so I don't expect to hear from him anytime soon, and in previous correspondence, he said he couldn't recommend his method, whatever it was.)
NSWorkspace
notification + some private API to getSpaceID
. With that you can launch your script. Note SpaceIDs might be "out of order" if you've moved them around, so I'm not sure if that number is helpful. Mine are for example (from leftmost) 3,5,2,12,13