I'm trying my initial experimentation of linking KBM with the free program CurrentKey Stats. CKS is a pretty good destop/workspace manager, you can assign hotkeys to switch to a different workspace and give the workspaces, which CKS calls Rooms, useful text names instead of the Mission Control names Desktop 1, Desktop 2, etc.
The simplest use of that seems to be to find out the name of the current workspace (which CKS calls a Room). The CKS doc on the above web page says that is simply:
tell application “CurrentKey Stats” to getactiveroom
The doc says that returns text.
I'm running it inside the Keyboard Maestro action, Execute AppleScript:
When I run that, the KBM script fails.
The error that gets logged is:
2021-01-20 00:34:47 Execute an AppleScript failed with script error: text-script:17:18: script error: Expected expression, property or key form, etc. but found unknown token. (-2741). Macro “Display Current Room Name from CurrentKey” cancelled (while executing Execute AppleScript).
I'm a newbie at AppleScript (which in its wordiness reminds me of COBOL) so I don't know what obvious syntax might be missing. Is there supposed to be an explicit handling of the result or does it have a STDOUT concept?
Does anyone have a clue what the issue is?
I'm asking the CKS developer too. It's tricky when trying to get two apps to communicate.
Hi @August,
Try replacing the AppleScript in your action with this
tell application "CurrentKey Stats"
set var to getactiveroom
end tell
I don't have CurrentKey Stats so I can't test it. The result you're looking for is in the variable var
Hope that helps.
EDIT: I just tried the form of AppleScript that you used with another application and it worked OK. I thought that not assigning the result to a variable would mean it would not be returned to KM. So - if what I suggested still doesn't work you will need to check that you have set up access to CurrentKey Stats using whatever instructions their documentation gives. (cf "Background Services panel").
Knowing that the AppleScript syntax works with another app is a forward step.
I has also been wondering about the setting the in CKS Background Services panel. Like KBM, generally changes in CKS are effective immediately, but just in case, I checked the setting again and then stopped and restarted CKS. The setting was still there, but the functionality was not.
I've passed your test results on to the developer. I had narrowed it down to either the CKS/AppleScript interface or my AppleScript syntax, and you've helped with that side of it.
UPDATE: I tried your script above, with one additional line:
tell application "CurrentKey Stats"
set var to getactiveroom
end tell
return var
I didn't even go looking in AppleScript doc for how to do that, I just guessed based on how wordy the language is that command might be something like that.
That worked!
There was an intermediate step in which I got this dialog:
When I clicked OK, a text window popped up, as in my script, with the name of the current room displayed.