Font Selection Issues

Where do you see that? Imo, Apple doesn’t give a damn anymore about AppleScript and JXA. The only difference being that JavaScript (ie the language powering JXA) gets new features. Because Safari needs them. So, scripting with JXA becomes easier, while the kinks in the OSA binding remain.
And yes, there’s some AI slop on JXA out on Amazon, too. The “author” even rooted for that stuff on MacScripter some months ago.

The book, which was the subject of my post, is what I was referring to in relation to its view of Apple’s treatment of JXA vs AppleScript.

Your view aligns with mine (which I made clear) that Apple has effectively abandoned both for substantive development.

Sean

a.m. = array methods?

There was some talk on the net in the last few years about a renaissance of JXA. Mostly in the context of admin tasks and security research. I guess the AI misinterpreted that. Apple is doing zilch with JXA, only with the JS engine itself.
Which could be helpful in automation, as the. Omni-line of products and Drafts show, because pure JS works on macOS and i*OS. But it does not offer the possibility to talk to scriptable apps out of the box. Rock, hard place.

chrillek: Well … I don’t know that I’m enthusiastic about learning how to script, but I do see how useful it can be. Your point about AS vs JavaScript is well-taken and something to seriously consider, given the constraints I have on the time I have available to devote to this learning curve.

Your script did the same thing as Bluefrog’s but I note that yours was written in Java, which confirms what I’ve also read in this threat that DT doesn’t care if the script is written in Java or AS. Since AS is Apple’s proprietary language, it certainly makes more sense to go with Java.

Thanks for your observations!

1 Like

It was written in JavaScript which has nothing to do with Java. Except for an unfortunate naming similarity.
The difference does matter.

1 Like

chrillek:

Thanks for pointing this out - I could easily have taken the wrong fork in the road!

You don’t have to do each file one-by-one. You can select multiple documents and process them with one run of the script. It’s built for it.

2 Likes

Bluefrog:

I must be doing something wrong, then. The only way I have been able to process the files is to click the diagonal arrow at the top of the annotation file box so that the file is enlarged. The script doesn’t run if I don’t do that. Likewise, it doesn’t run if I select multiple files in the group. This isn’t a big deal - your script has already saved me a lot of annoyance at having to scroll down in the font selector box. Thank you for writing it - perhaps someone else will find it useful also.

If you select multiple files in the item list, it filters out anything but RTF(D) files and acts on those it finds, e.g.,…

I guess you tried selecting files with an annotation? As it is, the script doesn’t work on such a selection. You need to select the actual annotation files themselves.

Both @BLUEFROG’s and @chrillek’s script process multiple files in one go. They are written to execute a set of commands on all “selected records”.

All items in a database are referred to as “records”. Groups, smart groups, tags, documents, annotations—they are all “records”. You’ll see this term in almost every DEVONthink script.

selected records (AppleScript) or selectedRecords (JavaScript) refers to your selection in the item list. If the front window is a document window, which has no item list, selected records instead refers to the record displayed in the window. (In a sense you selected it by opening a separate window for it.) That explains why the script does work when you open the annotation in its own window.

If you want a script that runs on the annotations files of your selection, it could look like this AppleScript:

tell application id "DNtp"
	set theRecords to every selected record's annotation
	if theRecords = {missing value} then return
	repeat with theRecord in theRecords
		if (record type of theRecord is in {RTF, RTFD}) then
			tell (rich text of theRecord)
				set font to "Georgia"
				set size to 18
			end tell
		end if
	end repeat
end tell

However, this won’t do anything if you run it after opening an annotation file in its own window.


By the way @chrillek, I don’t think you need to use attributeRuns if you just want to apply global changes. This seems to be enough:

records.forEach(r => {
	r.richText.font = "Georgia";
	r.richText.size = 18;
})

// Or
records.forEach(r => Object.assign(r.richText,
	{font:"Georgia", size:18}));
2 Likes

troejgaard:

“I guess you tried selecting files with an annotation? As it is, the script doesn’t work on such a selection. You need to select the actual annotation files themselves.”

Yup! I knew I was doing something wrong! Thank you for pointing my error out. My improved workflow just got even better! :smile: I just processed 8 annotation files in about 3 seconds by selecting them in the annotation database after creating them by copying and pasting the Gemini transcription into the annotation box. If I had only known this 5,000 files ago … Maybe someone else will read this post and benefit by doing so.

Thanks for taking the time to educate me further.

2 Likes

You’re welcome!

Going forward, you could even apply such a script to any new annotation files automatically on creation with a smart rule.

You need a scope targeting just your annotations, so this assumes that you use the default annotations group. Here I selected Global Inbox > Annotations

The magic happens in the “Apply Script” action. Set it to either “AppleScript” or “JavaScript” and click the “Edit Script…” button. This gives you a popup where you can enter your code.

A script for a smart rule is slightly different as you need to wrap your code in a performsmartrule function (JavaScript) or on performSmartRule handler (AppleScript).

Like chrillek I prefer JavaScript:

function performsmartrule(records) {
	const app = Application("DEVONthink");
	app.includeStandardAdditions = true;
	
	records.forEach (r => {
		const txt = r.richText;
		txt.font = "Georgia";
		txt.size = 18;
	})
}

In AppleScript it would look like this:

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			tell (rich text of theRecord)
				set font to "Georgia"
				set size to 18
			end tell
		end repeat
	end tell
end performSmartRule

I’m not sure what trigger would best fit your workflow. “On Creation” works when I paste into the empty annotation field in the inspector, though with a little caveat. The annotation file is only “created”, thus triggering the rule, when I move focus away from the field.
If I instead use the dropdown menu and select “New With Clipboard”, the rule triggers immediately.

3 Likes

This is not a topic which concerns me personally at the moment but I wanted to thank @chrillek , @troejgaard and @BLUEFROG for the valuable inputs and examples they are taking the time to produce and share with us. This knowledge will benefit many current and future DEVONthink users. :folded_hands:t2:

5 Likes

:heart:
Thanks for the kind words. Nice to read on a Friday (or any other day ending with a “y”) :wink:

2 Likes

troejgaard:

This probably won’t work well for my workflow. Short explanation:

I’m using Gemini to create the transcriptions which become annotation files. Gemini doesn’t always produce what I expect for a variety of reasons. I try to process 10 files at a time, which doesn’t always work due to the size of the files to be processed, so I often have 10 individual potential annotations in one Word document to “attach” to 10 different clippings, which are usually not in the same group. Gemini also doesn’t pay a lot of attention to the order specified in the chat prompt so a file could be attached to the wrong clipping. I spend a significant amount of time paying attention to these potential glitches so automating the process to the extent your script does might create even more work for me. But for someone not working with old newspaper clippings, it might be the cat’s meow. I’m sure there are others who have already copied your script and using it to save time. I hope those using it take a moment to thank you for your work.:clap:

troejgaard:

I just processed 63 files in less than 3 minutes. Without your script, it would have taken me a good 30 minutes. A huge thank you!!!

1 Like