Change Fonts in Multiple Notes

This seems to have come up a few years ago, but I haven’t found an answer as yet. I’ve imported my notes from RTFD files. Of course, the default font seems to be Times New Roman, but I would like to change it to Arial. I found a couple of Applescripts posted in older topics but none seem to work a few years later. Is there a way to select multiple notes and change the font thru automation?

AppleScript is still the only option.

1 Like

And the script can be incredibly simple if this is for a one-off purpose and it’s changing all the text in rich text documents to one font.
Here’s a one-liner…

tell application id "DNtp" to set the font of the text of (selected records) to "AvenirNextCondensed-Regular”

You’ll want to check out and specify the Postscript Name found in the Font Book app…

PS: In this form you don’t need to be displaying the content of the document.

Thanks. But…what if there is formatting (bold, color, etc.) and I want to maintain that?

I’ve tried this after the info about using the FontBook Postscript Name:

tell application id "DNtp"
	set theSelection to the selection
	if theSelection is {} then error "Select an item, please"
	repeat with theRecord in theSelection
		try
			tell text of theRecord
				set (font of every attribute run whose (font contains "Bold")) to "Arial-BoldMT"
				set (font of every attribute run whose (font contains "Italic")) to "Arial-ItalicMT"
				set (font of every attribute run whose (font does not contain "Bold" and font does not contain "Italic" and font does not contain "Verdana")) to "ArialMT"
				(*
set alignment of text to left
set paragraph spacing of text to 20
set line spacing of text to 5
*)
				reformat text
			end tell
		end try
	end repeat
	display alert "batch processing completed" giving up after 1
end tell

But this still doesn’t change the font.

I got that code from a four year old post I found. I thought maybe it failed because I just had the font listed as Arial. But even after using the Postscript name, same, no joy.

PS: I thought using <code> before the script and after would format it correctly. Sorry it didn’t.

Please post code included in three backticks like so
```
code goes here
```
No need to manually emphasize anything than. And the code is easier to read (a lot), can be copied/pasted elsewhere etc.

We’re in Markdown land here, not HTML. So, you have to escape < with a backslash like so \<

That’s an optimistic approach – fonts can be named whatever, and the attributes Bold or Italic can be in lower case…

Got it! Sorry I used something else which obviously did not work. Will make a note about the backticks.

Should I repost the script correctly? (I’m new here.)

No, just fix it. Use tthe pencil under the post to open the editor again. I would’ve done it, but it was too much work for me. You could simply remove the wrongly formatted script, add the backticks and then copy/paste the original code verbatim between those.

tell application id "DNtp"
	if selection is {} then return
	
	repeat with theRecord in (selected records)
		if (type of theRecord is in {rtf, rtfd}) then
			tell text of theRecord
				set font of (every attribute run whose font contains "Bold") to "AvenirNextCondensed-Bold"
			end tell
		else
			display alert "This is not a rich text file!"
			return
		end if
	end repeat
end tell

This changes the bold font as expected and it includes a little error trapping.
And yes it works with the Arial font…

set font of (every attribute run whose font contains "Bold") to "Arial-BoldMT”

PS: Code block fixed above.

I apologize for being so ignorant. Coding has never been my strong suit. I received a lot of help from Joe Kissell who wrote the Take Control of DT book. Saying that was to remind me that a bunch of the Notes (trying to get away from Apple Notes) that many of them are actually of Kind Formatted Note. Is there a means I can add something about that to the if (type of theRecord is in {rtf, rtfd}) then part of the Applescript?

No worries but you need to be specific when inquiring about these things.
Changing a font is one thing,
Changing a font while preserving attributes like styling, color, link state, etc. is a totally different inquiry.

And no, you can’t use the same routine on formatted notes or HTML. If you don’t have a compelling reason to leave them as formatted notes, I’d convert them to rich text and post-process them.

“Formatted Note” is a long way to say “HTML”. With HTML, it’s quite easy to change the font, as you do not need to modify the document(s) themselves – simply providing the approprate HTML suffices.

I’d take a different stance on that one: If you don’t have a compelling reason for them to be HTML, convert them to Markdown. That’s a lot easier to manage than RTF, and it allows styling in a separate file (again: CSS). Mixing formatting and text in the same document has always been a terrible idea …

There are millions of people in the world that disagree with you on this, including people who have gotten very rich providing that experience :wink:

And as much as I love my Markdown, rich text is still a very useful format for many people.

1 Like

I don’t understand “simply providing the approprate HTML suffices” What do I need to do instead of the Applescript to change the font?

Oh, wait, I think I’ve heard of Mr Gates. But I was not talking about “terrible idea” in the sense of “bad for the stock value” :wink: But the debate about integrating text and representation vs. keeping them separate is fairly old. And even in the world of “lets keep them in the same place”, there are better (TeX) and worse (RTF) cases, I think.

If you look at the current thread: It’s not even possible to access only bold attribute runs, as someone (Apple?) threw this attribute under the bus somewhere (together with italic, it seems). So, I can set something to bold, but I can’t inquire it? Whereas underline is set- and getable? Who invents this kind of stuff?

I’d probably need to convert to RTFD as many of the notes have imbedded images. So, I could convert them but is this something I would do from within DT or wipe the database, convert the HTML files with something like textutil and then reimport those? (I just looked and I already have the RTFD files of all the same notes. And, it looks like when I exported the notes from Apple Notes using the Exporter app, is when the notes changed from Arial in Apple Notes to Times New Roman. So perhaps importing those RTFD notes after wiping the database, or just creating a new one, I could use Bluefrog’s Applescript to change the font?)

I see no need to start from scratch. You can use Data > Convert > To Rich Text to convert files in place.

Very much appreciated. This only acts on Bold elements. If the regular text is Times, nothing happens. Can I just add

set (font of every attribute run whose (font does not contain "Bold" and font does not contain "Italic" and font does not contain "Verdana")) to "ArialMT"

below the element

set font of (every attribute run whose font contains "Bold") to "AvenirNextCondensed-Bold"