WhichSpace
WhichSpace copied to clipboard
Call a script whenever the space changes
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 Chrome tab list feature (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. If I'm reading a PDF and click a link, it will open a new tab in whatever happened to be the most recently used browser window, whatever desktop space that happens to be in.
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, in this case it's /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.
One of the features of CKS is that spaces (Spencer calls them Rooms) can have text names of 16 or 17 characters and you can edit those names as you wish. To replicate that, I would at least need to know whenever the current space changes and where I am now, by number. Then I can look up what the name is to display it, etc.
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.
Similarly, could it be possible to query for what the active space number is?
Is that currently possible in WhichSpace? If not, could it be?