Jaysce / Spaceman

A macOS app to view Spaces / Virtual Desktops in the menu bar
https://www.jaysce.dev/projects/spaceman
MIT License
740 stars 29 forks source link

Call a script whenever the space changes #15

Open AugustM opened 2 years ago

AugustM commented 2 years ago

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.

One of the features of CKS is that spaces (Spencer calls them Rooms) can have text names of 16 or 17n 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 then 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.

Is that currently possible in Spaceman? If not, could it be?