Thanks @Nige_S,
The tell
blocks are in the notify:
section because that's where they are meaningful.
My understanding is that the run
block runs once, when the app starts. That's where the Observer gets initiated. The tell
blocks inside that get the current values of the Desktop Number (from WhichSpace) and Room Name (from CurrentKey) for the current Desktop Workspace.
Then, if understand it correctly, the notify:
block gets run every time the Observer sees that NSWorkspaceActiveSpaceDidChangeNotification
is true
, meaning that the Active Space changed, whether manually, automatically, by Mission Control or some app, it doesn't matter. So the first thing the notify:
block does is re-do those tell
blocks to WhatSpace and CurrentKey to find out what the new values of Desktop Number and Room Name are, saving the previous values as ...Previous
values.
Then it calls the KBM macro, hopefully passing it the four values of Current Number and Name and Previous Number and Name. (Right now, the KBM call with the parameter, eventually a 4-tuple, is commented out while I attempt to get the rest working.)
Maybe you're right, maybe I'm trying to pack too much activity into the notify:
block and asking it to keep track of all my variables rather than have it simply do the single task of notifying.
My previous version of this, where I did just that, and let KBM call WhichSpace and CurrentKey and keep track of the values, worked just fine, as far as I got with it. So if this doesn't shake out quickly, I'll revert to that.
It just seemed to me that it would be somehow more "efficient" to do all the AppleScript at once, in one place, instead of having AppleScript Notify KBM of the Space change and then have KBM turn around and ask AppleScript to get the Space Number and Room Name from WhichSpace and CurrentKey.
Maybe that's a mistaken idea of "efficiency". I've seen AppleScript debugging threads on Stack Overflow and Ask Different where someone explained that it didn't work to have the app name in a tell
block be specified by a variable because the AppleScript interpreter looks at what app you are talking to and interpret the rest of your commands within that context, with different terms and functionality available for different apps. Maybe it's like that, where the AppleScript interpreter has a limited idea of what someone will be doing or would ever want to do within a notify:
block, and it gets confused when I try to do non-notifying kinds of things.
As I said above, I have a working route that I can revert to, I just thought this would be somehow "better". And maybe it's a case of Apple insisting that Apple knows best.
Thanks.