# How do I batch Summarize selected notes or a group?

**URL:** <https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742>\
**Category:** DEVONthink\
**Tags:** automation\
**Created:** [April 28, 2022, 11:53am UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742 "2022-04-28T11:53:50Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![tacotuesday](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/13edae/32.png) [@tacotuesday](https://discourse.devontechnologies.com/u/tacotuesday)\
**Post date:** [April 28, 2022, 11:53am UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/1 "2022-04-28T11:53:50Z")

</div>

I would like to automate the use of DEVONthink’s Summarize service on multiple notes. I currently select a note, click inside, hit `Cmd + A`, then use the system-level hotkey I’ve assigned to the Summarize service. This is very cumbersome for groups of many similar results, such as the results automatically imported from the first few DEVONagent search set results. How could I automate the service so that I could select either a group or a selection of files, then run the Summarize service for each file? Many thanks!

---

<div class="post-metadata">

**Author:** ![cgrunenberg](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/cgrunenberg/32/7172_2.png) [@cgrunenberg](https://discourse.devontechnologies.com/u/cgrunenberg)\
**Post date:** [April 28, 2022, 12:56pm UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/2 "2022-04-28T12:56:30Z")

</div>

Although the results are usually not identical, the `summarize` AppleScript command found in the standard additions might be useful.

---

<div class="post-metadata">

**Author:** ![tacotuesday](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/13edae/32.png) [@tacotuesday](https://discourse.devontechnologies.com/u/tacotuesday)\
**Post date:** [April 28, 2022, 11:07pm UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/3 "2022-04-28T23:07:25Z")

</div>

Thanks! Is that the macOS service? I could only find `summarize highlights of` and `summarize mentions of` in the DEVONthink dictionary.

---

<div class="post-metadata">

**Author:** ![pete31](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/p/d26b3c/32.png) [@pete31](https://discourse.devontechnologies.com/u/pete31)\
**Post date:** [April 28, 2022, 11:34pm UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/4 "2022-04-28T23:34:40Z")

</div>

> [@tacotuesday](#):
>
> Is that the macOS service?

Yes, it’s the same as the service.

> [@tacotuesday](#):
>
> I could only find `summarize highlights of` and `summarize mentions of` in the DEVONthink dictionary.

It’s not a DEVONthink AppleScript command.

You’ll find in the `StandardAdditions`:

- Open `Script Editor.app`
- Menu `Window > Library`
- Click `StandardAdditions`
- Search `summarize `

Here’s a capture taken from [Script Debugger](https://latenightsw.com/)’s dictionary window:

 ![1](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/8/0/808f606a474ee6ccd57323032d77a6d31f8301d5.png)

---

<div class="post-metadata">

**Author:** ![tacotuesday](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/13edae/32.png) [@tacotuesday](https://discourse.devontechnologies.com/u/tacotuesday)\
**Post date:** [April 29, 2022, 11:35am UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/5 "2022-04-29T11:35:24Z")

</div>

Thanks, @pete31. I have a lot of trouble navigating Applescript so I appreciate the in-depth assistance. (And thank you for mentioning Script Debugger!)

I tried to adapt [Blanc’s highlight summarization](https://discourse.devontechnologies.com/t/summarize-highlights-as-markdown-on-toolbar/64068/6) script to summarize rather than summarize highlights by changing:

```auto
summarize highlights of records {thisItem} to sheet in theDest # or use "markdown" or "rich" instead of "sheet"

```

to

```auto
summarize {thisItem} in 10

```

I keep getting a type error: `DEVONthink 3 got an error: Can’t make {content id 104975 of database id 2} into type string.` Is this because I am trying to operate on a record, and I need to do something like this?

```auto
set someVar to get plain text of {thisItem}
summarize someVar in 10

```

---

<div class="post-metadata">

**Author:** ![pete31](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/p/d26b3c/32.png) [@pete31](https://discourse.devontechnologies.com/u/pete31)\
**Post date:** [April 29, 2022, 12:04pm UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/6 "2022-04-29T12:04:37Z")

</div>

> [@tacotuesday](#):
>
> I tried to adapt [Blanc’s highlight summarization](https://discourse.devontechnologies.com/t/summarize-highlights-as-markdown-on-toolbar/64068/6) script to summarize rather than summarize highlights by changing

This won’t work as these are completely different things.

Take a look at the capture, the “type” for “direct parameter” is `text` or `alias`, which means there are two different things we can throw at this command either some text …

```auto
-- Using StandardAdditions's "summarize" by providing text

tell application id "DNtp"
	try
		set theRecords to selected records
		if theRecords = {} then error "Please select a record"
		set theRecord to item 1 of theRecords
		set theRecord_Text to plain text of theRecord
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

set theRecord_Text_summarized to summarize theRecord_Text

```

  

… or an alias.

```auto
-- Using StandardAdditions's "summarize" by providing an alias

tell application id "DNtp"
	try
		set theRecords to selected records
		if theRecords = {} then error "Please select a record"
		set theRecord to item 1 of theRecords
		set theRecord_Path to path of theRecord
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

set theRecord_Path_Alias to POSIX file theRecord_Path as alias
set theRecord_Text_summarized to summarize theRecord_Path_Alias

```

---

<div class="post-metadata">

**Author:** ![tacotuesday](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/13edae/32.png) [@tacotuesday](https://discourse.devontechnologies.com/u/tacotuesday)\
**Post date:** [April 30, 2022, 3:02am UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/7 "2022-04-30T03:02:19Z")

</div>

Thanks again, @pete31. I’ve had a little trouble working with the one for aliases. I did manage to hack together a script that will Summarize an arbitrary number of selected files and save the results as a Markdown file.

```auto
-- Batch Summarize selected files

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application id "DNtp"
	set theRecords to selected records
	if theRecords = {} then error "Please select a record"
	set theFinalSummary to ""
	try
		repeat with theRecord in theRecords
			set theRecordName to name of theRecord
			set theRecord_Text to plain text of theRecord
			set theRecord_Text_summarized to summarize theRecord_Text in 5
			set theFinalSummary to theFinalSummary & return & "## " & theRecordName & return & theRecord_Text_summarized & return
		end repeat
		
		create record with {name:"Selected Records Summary", type:markdown, plain text:"# Selected Records summary" & return & return & theFinalSummary} in current group
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

```

A nice quality of life improvement would be the ability to recognize and reformat Summarize results that are Markdown header-level text. Is there a more elegant way to write an output record from a ~~`for`~~ `repeat` loop?

---

<div class="post-metadata">

**Author:** ![pete31](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/p/d26b3c/32.png) [@pete31](https://discourse.devontechnologies.com/u/pete31)\
**Post date:** [April 30, 2022, 3:33am UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/8 "2022-04-30T03:33:20Z")

</div>

> [@tacotuesday](#):
>
> A nice quality of life improvement would be the ability to recognize and reformat Summarize results that are Markdown header-level text.

Not sure what that means. Could you explain what you’re looking for, maybe with an example?

> [@tacotuesday](#):
>
> Is there a more elegant way to write an output record from a ~~`for`~~ `repeat` loop?

Instead of appending to a string variable (`theFinalSummary`) I would collect everything in a list (`set end of theFinalSummary_list to XY`), then add the level 1 heading to the list and use this handler

```auto
on tid(theInput, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	if class of theInput = text then
		set theOutput to text items of theInput
	else if class of theInput = list then
		set theOutput to theInput as text
	end if
	set AppleScript's text item delimiters to d
	return theOutput
end tid

```

It probalby doesn’t make a difference, but it feels easier to figure out the desired output this way.

---

<div class="post-metadata">

**Author:** ![tacotuesday](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/t/13edae/32.png) [@tacotuesday](https://discourse.devontechnologies.com/u/tacotuesday)\
**Post date:** [April 30, 2022, 12:06pm UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/9 "2022-04-30T12:06:37Z")

</div>

> [@pete31](#):
>
> Not sure what that means. Could you explain what you’re looking for, maybe with an example?

Most of my Markdown files restate the file name as an H1 header. (I suppose that’s a habit rather than a requirement.) Many times the script captures the file “title” as something worth summarizing, so I frequently end up with results like this:

 ![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/9/c/9c69fd42d1489533925dcbc7a18d4bdc3f0c48b7.png)

This certainly involves some conditional logic that strips the header from the line (and perhaps removes the link using regex), but it has been a long week and I’ll just suffer through it for the time being. 🙃

> [@pete31](#):
>
> Instead of appending to a string variable (`theFinalSummary` ) I would collect everything in a list (`set end of theFinalSummary_list to XY` ), then add the level 1 heading to the list and use this handler

It is funny that you mention this. I found the same function in your `Create Markdown See Also List` script ([here](https://discourse.devontechnologies.com/t/how-to-export-the-results-list-for-the-see-also-classify-command/58661/28)) and it had me scratching my head. I suppose it’s worth going back to that script and studying that function.

By the way, I wanted to modify the `Create Markdown See Also` script in two ways that may be interesting or helpful, but I’m having trouble with both:

1. The script can’t handle notes that start with `>`. Many of my book notes start with blockquotes from the source material, so the script breaks frequently for me.
2. I wanted the text excerpt to use Summarize rather than the first `n` paragraphs.

---

<div class="post-metadata">

**Author:** ![pete31](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/p/d26b3c/32.png) [@pete31](https://discourse.devontechnologies.com/u/pete31)\
**Post date:** [April 30, 2022, 12:39pm UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/10 "2022-04-30T12:39:34Z")

</div>

> [@tacotuesday](#):
>
> Many times the script captures the file “title” as something worth summarizing, so I frequently end up with results like this

Use a repeat to check each line. If it starts with `# ` (note the space) throw it away. If it doesn’t add it to a list.

---

<div class="post-metadata">

**Author:** ![pete31](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/p/d26b3c/32.png) [@pete31](https://discourse.devontechnologies.com/u/pete31)\
**Post date:** [April 30, 2022, 12:42pm UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/11 "2022-04-30T12:42:05Z")

</div>

> [@tacotuesday](#):
>
> I wanted to modify the `Create Markdown See Also` script in two ways that may be interesting or helpful, but I’m having trouble with both:
> 
> 1. The script can’t handle notes that start with `>`. Many of my book notes start with blockquotes from the source material, so the script breaks frequently for me.

True. Please post it in the other thread.

---

<div class="post-metadata">

**Author:** ![system](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/2X/4/4e6ff70c96be2eb307a274d890bba8d71ba671b3.png) [@system](https://discourse.devontechnologies.com/u/system)\
**Post date:** [April 29, 2025, 12:42pm UTC](https://discourse.devontechnologies.com/t/how-do-i-batch-summarize-selected-notes-or-a-group/70742/12 "2025-04-29T12:42:18Z")

</div>

This topic was automatically closed 1095 days after the last reply. New replies are no longer allowed.
