Notification vs Text Briefly

I had this issue before and today I found a way to achieve this, thanks to @ccstone's post

So basically if we set the notifications to Banner
image

image

Then the Text Briefly action, is indeed briefly shown as expected.
Now the issue is that the Notification action will also be displayed briefly.

Using the Execute AppleScript action with the script provided by @ccstone

display notification "They're coming to take you away – Ha, Ha!" with title "Keyboard Maestro" subtitle "Is sending you a message" sound name "Tink"

we are able to have both notifications and banners.

So my question to @peternlewis is:
wouldn't it be possible to implement this as an action?
Like a "wrapper" where the action's UI is like the current Notification action, but what it's doing is running the above AppleScript?

That way we can have it set to Banners in the notifications window, but we would be able to have both options, which is useful.

Here's both
image

The only thing that can't seem to be customizable is the icon, but that's not an issue to me. Having both options is more important

I don't know what the benefit of Text Briefly over a notification is, although that's by the by.

You could make a KM plugin that does this if you'd like. It's a bit convoluted but it's doable.

I've made a start but, having only ever made two plugins, my inexperience is showing and I can't get it to import. Perhaps someone else can see what I've done wrong...? I probably would have been able to get it working a few weeks ago, when plugins were fresh in my mind. Oh well...

Display_Text_Briefly.zip (11.6 KB)

1 Like

Why not just create a macOS shortcut (using the Notification action, of course) and pass the values there?

The name of the macro is passed to the first line. The title of the macro is passed to the second line. The message of the macro is passed to the third line. That's how shortcuts work.

Screenshot 2023-11-29 at 17.48.12

I'm not sure if it's a better solution, but it's not a bad solution. Moreover, you can even change the icon in Shortcuts.

2 Likes

I could, but as you note it would display the Script Editor icon which is quite problematic. Also, if (Mac Automation Scripting Guide: Displaying Notifications) is to be believed, this is imply using Script Editor’s notification settings, so that is not great either.

It is highly unfortunately that Apple don't allow the API to set the notification style.

Apparently, so apps have separate sub-apps that do different notifications, just so you can have different notification settings, which seems a completely insane workaround.

I think a better solution if you want a wrapper for this is to use a Plug In action, which makes it clear as to why it does not have the Keyboard Maestro icon associated with it.

Ok I figured out why it wasn't importing, and this sort of works:

Display_Text_Briefly.zip (12.3 KB)

Caveats:

  • The sound doesn't work.
  • You can't set the notification icon.

Questions for @peternlewis :

  1. Is it only possible to use text input fields in plugins, or can we use a pop-up menu for things like notification sound choice?
  2. I noticed that some .scpt files for other people's KM plugins are nicely compiled in QuickView:
Screenshot

Mine, on the other hand can't be viewed by QuickView at all. If I use osacompile, they turn into unreadable unicode.

Screenshot

What am I missing there?

You can have popup menus. See the documentation: Plug In Actions

Looks like it is being saved as a compiled script rather than text. Which is probably good.

Trust me not to RTFM. Ok I've got that working.

Display_Text_Briefly.zip (12.4 KB)

The only issue now is that the sound doesn't work, even if I explicitly name it in the .scpt file. :man_shrugging:t2:

Ok thanks. Just odd that it doesn't look like the others. Maybe because they were generated by Script Editor rather than BBEdit?

Slightly off-topic:

As a more general point about plugins: They're very neat and handy, but I generally try not to use them in case I need to share the containing macro and forget to also send the plugin. I wonder if there's a practicable solution for that problem?

Flagrantly off-topic:

Mini-feature-request: when you export an action, it would be really nice if the subsequent save dialog was pre-filled with its actual name, rather than a generic one.

AppleScript scripts can be distributed publicly as either plain text files or compiled script files. When the author of an AppleScript doesn't want others to see how the script works, then they'll compile their text script as a run-only file which will prevent others easily seeing how the script works. The other (potential) benefit of compiling scripts is that they may run a bit faster than their plain-text counterparts (I know you have an interest in that).

That's why you can't read your compiled run-only script in any editor.

(Edit Note: Inserted run-only )

2 Likes

Makes sense, but what I'm wondering about is why some scripts are garbled in a text editor but also readable as colour formatted AS in QuickView.

Oh - OK. Can you post an example file?

Sure. Here's mine:

DisplayTextBriefly.scpt.zip (805 Bytes)

Here's a pretty one:

Action.scpt.zip (17.2 KB)

It just dawned on me: an AppleScript file with the extension .scpt can be either a plain text file or a compiled AppleScript file. I've used this fact in my own plug ins.

1 Like

This version of my script is compiled using osacompile. Still not viewable in QuickView:

DisplayTextBriefly.scpt.zip (1.4 KB)

This is what yours looks like to me in Script Debugger

image

That's because it's compiled. I.e. the file no longer contains the source (text) version of your script.

This is it in a hex editor

image

Plainly not readable text!

1 Like

There's a chance you've already answered this and I'm failing to keep up but...

Yes, I understand that. So why is this script, which appears also to be compiled, viewable in QuickView?

What makes you believe that?

Because in BBEdit it looks like this:

Screenshot

...and also because my understanding (which may be misguided) is that AS doesn't appear as colour coded like that until it's compiled.

Interestingly, it can't be opened in Script Debugger, as it's run-only. Perhaps that's the differentiator?

There are currently just two chances of that happening - big and fat (apologies to everyone who I might have offended...)

that's correct, and the places you can compile AppleScript are in an AS editor or through a shell command.

You can't compile AS in a text editor like BBEdit or TextEdit is because they don't understand AppleScript and because they don't understand it they also can't display compiled AppleScript. Obviously Script Editor, Script Debugger, QuickView do understand AppleScript and so they can display it...

(Side note: For some reason unknown to me I don't have QuickView on my Mac so I'm just assuming it's a bit more intelligent than BBEdit/TextEdit in this respect.)

The file you uploaded (17.2 KB) I can open in both SD and SE, so I can safely say it isn't a run-only version. Here's a run-only version of that script:

Action.scpt.zip (3.6 KB)

The difference between the text and compiled versions of an AppleScript is that the latter has been converted into bytecode and also retains most of the human-readable script. The former can't actually be executed until it has first been converted into bytecode so that's one reason a compiled script will start executing quicker than a plain text one. That also explains why you can display a compiled script in a suitable editor and it appears as human-readable.

A run-only version of a script is both compiled and stripped of its human-readable content, which is why you can't read it nor edit it.

Does this answer the question? - I think so but I'm not really 100%!

This section from an O'Reilly book gives some insight by the way:

Weird. This is what I see:

CleanShot 2023-11-30 at 12.26.56@2x

I think so. Thankyou. The only unanswered part is why QuickView likes the run-only scripts, but you don't have it so...

which app gives you that warning Neil? oh, I can see it's SD. That is weird.