Create a New Note From AppleScript

Re the issue of ‘just’ :roll_eyes: making RTF with a link, I think this thread (from the OmniOutliner forum) might help.

%-prefixed URL-encoding codes are not case sensitive by intent: see RFC 3986: Uniform Resource Identifier (URI): Generic Syntax. But code parsing those might decide differently, in which case the choice is the coder’s not the standard.

Aside the code at play here are encoding angle brackets. The first line below is the urlencoding of the last:

message://%3cdiscourse/post/41031@forum.eastgate.com%3e
message://<discourse/post/41031@forum.eastgate.com>

IOW, the angle brackets are enclosing an email address.

1 Like

Thanks!

I’m here to report I just implemented the AppleScript I outlined above. (Had to change my Doc name because Paul went the safe route and eliminated the spaces and apostrophe. But I don’t “hear” William Shatner if it doesn’t say “Captain’s Log.” :stuck_out_tongue_winking_eye:)
It worked great! (I was also using $SourceURL, Paul went with just $URL. I made $URL a $DisplayedAttribute and it was populated as intended.)

The email I “logged” was Nick Moore, PopClip developer, responding to my query at the PopClip forum about a Mail URI extension for PopClip. Said response is here.

Another example of a generous and responsive developer. I recommend PopClip as a very useful addition to MacOS. Have used it for years. (Mostly to look up words.)

2 Likes

It still works, you didn’t do what I wrote in the linked post in 2019 :slight_smile:

You first need to use the defaults write command. Without using it PopClip’s plist doesn’t contain the OtherURLSchemes key. That’s why defaults read didn’t find it.


In your thread on the PopClip forum Nick mentioned that one can simply add new URL schemes via -array-add. Didn’t know that, it’s a lot easier than my old approach. Thanks!

2 Likes

The discussions in this other thread may be directly relevant. In fact some of the scripts above in this thread bear a striking resemblance to scripts in that thread!

Plain vanilla AppleScript is not good at outputting rtf or quasi-rtf (or whatever it is) for the Tinderbox Text pane. I haven’t found a way to do that without going through the clipboard.

The discovery by @mwra that typing a character after a (plain text) url in Text makes it clickable is intriguing! (The “raw” link unfortunately looks a bit ugly but it could work if there were some way to trigger Tinderbox to look for and activate links.)

AppleScript can easily output plain text for the URL attribute in Tinderbox where it is immediately clickable. That’s why I suggest going that route rather than trying to place a link in the Text pane. It’s easy to implement.

But if your goal is to have a pretty link in the Text pane instead of, or in addition to, the URL attribute then you can convert the plain text message link AppleScript extracts from Apple Mail into rtf using textutil within an AppleScript and place the result on the clipboard for pasting into the Text pane as a clickable link that uses the subject line of the message.

This is a script as posted in the other thread that does this …

tell application "Mail"
	tell first item of (get selection)
		set theHTMLLink to "<a href=\"" & "message://%3C" & its message id & "%3E" & "\">" & its subject & "</a>"
	end tell
end tell
-- convert html to "rtf" link and place on clipboard for pasting wherever
do shell script "echo " & quoted form of theHTMLLink & " | textutil -format html -encoding UTF-8 -convert rtf  -stdin -stdout | pbcopy -encoding UTF-8 -Prefer rtf "

Here it is in a Shortcut, also posted in the other thread:
Mail Message URL to Clipboard

(Click with Safari to view/install Shortcut)

BTW, for recent macOS version, a Shortcut in the built-in Shortcuts app pinned to the menu bar may be more convenient than going the old Automator and Services Menu route. Either way, lots of things can be done quite easily without dependency on third-party apps.

1 Like

Thanks, Sumner. It’s interesting, how many ways we can accomplish a certain result.

In this case, though, I didn’t get a clickable link in RTF on the clipboard. I copied the script from the post using the copy icon in the upper right corner of the code block, pasted it into Script Debugger and ran it without errors. But plain text(?) was what was on the clipboard.


Screenshot of UnClutter clipboard manager.

Pasting into $Text showed same:

This isn’t essential for my use case, I’m good with the link in any of the $URL attributes. But I was interested in the technique, perhaps for use in my blog.

Is there something clearly obvious I’m doing wrong?

(To clarify, I’d already created a log entry for the email notification from the forum, using the solution developed in Paul Christy’s script above. That’s why the URL is populated there. Subsequent to that entry, I went ahead and tried the script, and simply pasted the result in to the existing $Text of that log entry to see if it was an rtf link. It didn’t get there by any other “automated” means.)

Finally, I am getting good use from Captain’s Log even now. I’m looking forward to some weeks’ worth of entries and beginning to do some experiments with linking and agents and so on.

Not “wrong.” But there is something you are doing differently or something different that you have on your machine.

I can:

  1. Select a message in Mail
  2. Run the script (either from Script Editor or by choosing the Short Cut from a menu in the Menu Bars)
  3. Click in the text in the Text pane and paste.

The result is a clickable link in nice format in Text. (Or anywhere else you paste the results where rtf is accepted.)

I’m guessing you may have a third-party clipboard manager or other app that interferes with the normal operation of the clipboard.

Those can provide benefits in some situations, and can be fun to play around with. But when I’m trying to think and get work done, as opposed to play with the process, I’ve found they can be more trouble than they’re worth.

Often the built-in technology on the Mac (together with Tinderbox of course😀) is more than enough to do things efficiently. Add-ons and utilities sometimes fall in the “nice but not necessary” category.

A few years ago I used vanilla AppleScript not unlike some I posted in the other thread and you see above to bring hundreds (actually I think thousands) of emails into Tinderbox. I sorted and organized them in themes, and then dumped the result into Pages to create a nicely formatted book with an index, all with Tinderbox as the only third-party app.

If you haven’t done so already, do have a look at the built-in Shortcuts app.

2 Likes

New question:

I have an $Edict in p_Day :

$MyString="Midwatch";
create($MyString);

This worked on Friday. Of course, it was the middle of the day since that’s when I wrote it.

Today, it isn’t working. The $Edict is inherited from the $Prototype p_Day. It is enabled in the Saturday, March 9, 2024 container.

It won’t run, even with “Run now”.

Consulting aTbRef, I noted that,

but if nameStr is a unique note $Name, a new note is created as a new (last) child of the current note.

and

Essentially, the two-input form allows 3 forms of variation:

different path, different name (via two nested loops—one for paths, one for names)
different path, same name (loop with path variants)
same path, different name (loop with name variants)

This implies to me that “Midwatch” is a “unique” note $Name, as long as it’s in a “different path.”

So, why won’t this work?

I thought I had the whole “Create” thing down.

Also, thinking I had made it too complicated by using $MyString, I changed it to just the simple command:

create(“Midwatch”);

Also not working. And I checked, no curly quotes.

To recap: Worked on Friday. Won’t work on Saturday. Unique $Paths.

The code works for me both as an edict and as a stamp. But, using the create(noteName) syntax it appears that if noteName is a note $Name, then it must be unique to the whole document. In my text, once a single “Midwatch” note is present in the TBX, this code:

$MyString="Midwatch";
create($MyString);

has no result even if run in a different container to that holding the existing ‘Midwatch’. If you intend many containers to have their own ‘Midwatch’ child, then (tested!) you prototype $Edict should be:

$MyString=$Path+"/Midwatch";
create($MyString);

Guests arriving shortly, but I’d accept the ‘bare name’ syntax variant requiring the the name to unique at whole document scope and not just the current container could be made clearer in my aTbRef notes.

I think this is one of these obvious-after-the-fact things where Tinderbox is being cautious that you aren’t unintentionally spamming the TBX with loads of new notes. If there is no path element in the argument string, Tinderbox is clearly ultra cautious and allows you one note of that name per doc. Give it a path (as per my modified code), and you get one per target container. I don’t think the app defaults are bad, I just need to explain them more clearly … now I’m aware of this limitation.

†. I mean, it’s not as if we ever make mistakes writing action code and ask the app for an outcome we didn’t intend. :slight_smile:

1 Like

Roger all. Thanks!

1 Like

create([containerStr, ]nameStr) updated.

1 Like