How to Get Symbols Into an AppleScript Notification

I've been working on a Desktop/Workspace switcher. This issue I'm reporting here is about how to properly display the names of the workspaces when I include symbols in those names.

I didn't have any problem when the names of desktops were just text, but when I included symbols, here's the kind of thing that I had been seeing:

AppleScript Display Notification

This notification shows me the new desktop that I'm in as well as what desktop I came from. I've included symbols in the names of my most frequently used desktops where I've assigned a single-stroke hotkey combination. The names in that image are "Music ⌥⌘M" and "To Do Lists ⌥⌘T". When I switch desktops back the other way, the "To Do Lists" title then displayed properly and the "Music" name got garbled. They all displayed properly in the KM Prompt With List and anywhere else the name was used. Except in this notification.

I managed to narrow down the problem to the AppleScript "display notification" command in the AppleScript file that I created, that gets called by CurrentKey Stats (see below for more on this app) every time there is a desktop (room) switch. The script has the name of the current desktop/workspace/room available (as the AppleScript parameter roomName) and I was saving that in a text file to pull out as the name of the previous desktop after a switch.

When I look at the saved text file with an editor, the symbols are there, as the are supposed to be. At first I thought that maybe one field in the display got handled differently, but when I switched the text positions, the problem followed the text. That means the core of the issue was the reading of the file where I save the previous name.

Here's the relevant code that creates the problem:

  set thePreviousRoomNameText to paragraph 1 of (read file theAppleRoomNameFile as text) as text
  set displayMessage to "Moved from '" & thePreviousRoomNameText & "'"
  display notification displayMessage with title roomName

After a couple of hours (!) searching around through AppleScript doc and StackExchange questions, I was still stumped, so I went to bed thinking that I would try doing the notification from within KM rather than AppleScript. At least KM could have a persistent variable, unlike AS which has a fresh instance every time it's called, so maybe if I didn't save the name in a file I could avoid the glitch that was happening when I read the file.

Then this morning I looked at one of my research pages with a fresh eye. It was a question on r/applescript on Reddit. It had two concepts in it that were new to me, one was "class utf8" and the other was that it actually should be «class utf8» with chevrons instead of quotes.

That worked.
AppleScript Notification Works

Here's the changed code. The only change is changing text to «class utf8» in one place.

  set thePreviousRoomNameText to paragraph 1 of (read file theAppleRoomNameFile as text) as text
  set displayMessage to "Moved from '" & thePreviousRoomNameText & "'"
  display notification displayMessage with title roomName

I still don't understand what the chevrons mean, exactly, in AppleScript, but regular quotes don't work. I has something to do with "raw mode" that I haven't figured out yet. If you know enough AppleScript to explain it, I'd be interested. But for now it's sufficient that it works.

As for building my own desktop switching macros that created this problem, here's the background. I've explored Jim's Desktop Spaces • Macros for Navigation and Window Management v1.1 in depth and he has some really good ideas (and for some reason I referred to him as "Dan" when I originally posted this), but I have been wanting something that goes even further for a while.

I'm using CurrentKey Stats, a free (but unfortunately discontinued) app that manages desktop workspaces using text names instead of the Mission Control Numbering scheme. That's huge for me because I have over 20 desktops and I can't remember all those numbers and in addition I like to rearrange the order so that I have the ones that I'm using together right next to each other, which lets me use the ⌃⬅︎ and ⌃➡︎ hotkeys instead of more complex ones or a menu. That's faster and more intuitive for me.

CurrentKey allows you to assign hotkeys to desktops, just about any hotkey you want. Jim's macro package also uses hotkeys, in a very consistent naming pattern based on the Mission Control numbering. Both systems use up a whole lot of hotkeys when you have a lot of desktops so the risk is high, in various ways, that they will trip over hotkeys used for other purposes. For instance, after taking the above screenshot, I discovered that if Chrome is the active window, the hotkey ⌥⌘M for my Music desktop will minimize all Chrome windows. That's not as bad as my previous discovery, the hard way, that ⌥⌘Q in Chrome instantly closes all tabs and windows. Yow.

To get around having a separate hotkey for each desktop, I have been wanting to use the magic of KBM's palettes to have the equivalent of a two-stroke hotkey, one to invoke the menu and one to pick. This name display issue around «class utf8» was simply the latest glitch in making that work the way I want it to.

I hope my story was useful.

Hi @August. Based on the link above and our previous correspondences, I'm assuming you are referring the shortcuts I shared. Dan? I don't even have a relative named Dan. :rofl:

BTW, rather than using a link to the top of the thread, I've been directing people to Desktop Spaces • Macros for Navigation and Window Management v1.1— Post #6, because it is there that I provided a major upgrade that superseded the information in Posts #1 to #5.

You say hotkeys here, but I think you really mean macOS Keyboard Shortcuts, right? At least when we have been previously corresponding, the bulk of our discussion was related to the Keyboard Shortcuts for Mission Control:

As I mentioned previously, the macros I shared use these macOS Keyboard Shortcuts because there is no Public API to move to a specific desktop. You may recall that I said that changing these assignments would be possible, but it would require some corresponding changes to the macros. (BTW, it would actually be pretty simple because I embedded these Type Keystroke actions in a single Group action within the macros.)

Back to Hot Keys...

With respect to the Hot Keys used to trigger the macros I shared, reassignment (or deleting them) can be done quite easily. There are no dependencies from one macro to another, with one exception: the single-action macros related to the optional Conflict Palette.

Now that subroutines are available in Keyboard Maestro 10, those single-action Conflict Palette macros that currently use the Remote Trigger action could be converted to use the Execute a Subroutine action. That change with some simple changes to Go to Desktop N and Move to Desktop N (converting them to subroutines), would allow you to deassign all hot keys and drive all macro functions via a Conflict Palette.

You got me; I have no idea. Is there a Dan in this group who does interesting macros? I'll fix it. Don't want to keep confusing people a year from now...

You may be thinking of @DanThomas who has more than a few interesting macros on the forum.

Search results for '@DanThomas' - Keyboard Maestro Discourse

Well, no, I don't think so. Is there a distinctive difference from a user's perspective, except for where they are defined? I tend to refer to any key that triggers an action as a hotkey. From a user perspective, the Keyboard Maestro "hot keys" or "hotkeys" in some ways share a namespace with the "shortcuts" defined in the MacOS Settings > Keyboard > Shortcuts > Mission Control dialog. I suppose there may be a need to distinguish "shortcuts" as those defined in that dialog and "hotkeys: as how you trigger a Keyboard Maestro macro because they are not exclusive. Using the defined MacOS shortcut, if it is also a KM macro trigger, can result in both actions being performed.

Sorry I wasn't clearer. I was using KM macro hotkey triggers and MacOS keyboard shortcuts very sloppily interchangeably.

That must be who I was thinking of. I downloaded Dan's KMET macro set to use in conjunction with my changing Jim's Desktop Spaces macros both this past week. Both guys have been very helpful and I guess, as much as I hate to admit it, I must have been having "a senior moment". Feh!

1 Like

Then you MUST have been talking about me, because I have those all the time!


@August, no problem, I get those too.

On a related note, I just uploaded a macro you might find useful: MACRO: Forum Username Tool, v1.0

Even if you don't want to use the macro, this excerpt from the header comment might help you out...

1 Like