# How to open Record with specific comment

**URL:** <https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039>\
**Category:** DEVONthink\
**Tags:** automation, devonthink3\
**Created:** [July 26, 2022, 8:03am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039 "2022-07-26T08:03:24Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fuguexv](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Fuguexv](https://discourse.devontechnologies.com/u/Fuguexv)\
**Post date:** [July 26, 2022, 8:03am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/1 "2022-07-26T08:03:24Z")

</div>

I was using Devonthink and Omnifocus at the same time, and I wrote two scripts with the help of my friend. The first script allowed me to create a folder with the same name for the tasks in Omnifocus and write the task’s ID to the comment of this folder, and the second script was to open this folder with Finder

The first script looks like this

```auto
tell application "OmniFocus"
	tell default document
		tell the front document window
			set theItem to selected tree of content
			set thePath to POSIX file "/Users/Fuguexv/Library/Mobile Documents/com~apple~CloudDocs/2022AU/2022AU_Inbox" as alias
			repeat with thisItem in theItem
				set folderName to name of thisItem
				set folderId to id of thisItem
				tell application "Finder"
					activate
					make new folder at thePath with properties {name:(folderName), comment:(folderId)}
				end tell
			end repeat
			say "OK"
		end tell
	end tell
end tell

```

The second script looks like this

```auto
tell application "OmniFocus"
	tell default document
		tell the front document window
			set theTask to selected tree of content
			repeat with thisTask in theTask
				set taskId to id of thisTask
				tell application "Finder"
					activate
					set rootFolder to POSIX file "/Users/Fuguexv/Library/Mobile Documents/com~apple~CloudDocs/2022AU" as alias
					set theTaskFolder to entire contents of rootFolder
					repeat with thisTaskFolder in theTaskFolder
						set folderComment to comment of thisTaskFolder
						if taskId contains folderComment then
							reveal thisTaskFolder
						end if
					end repeat
				end tell
			end repeat
		end tell
	end tell
end tell

```

Now I want to use **Devonthink** to open this folder, I tried to modify the second script but it didn’t work, I hope someone can help me to see what the problem is ~ thanks for your help!

My failed script looks like this

```auto
tell application "OmniFocus"
	tell default document
		tell the front document window
			set theTask to selected tree of content
			repeat with thisTask in theTask
				set taskId to id of thisTask
				tell application id "DNtp"
					set theRecord to lookup records with comment taskId
					repeat thisRecord in theRecord times
						open window for record thisRecord
					end repeat
				end tell
			end repeat
		end tell
	end tell
end tell

```

---

<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:** [July 26, 2022, 8:09am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/2 "2022-07-26T08:09:55Z")

</div>

> [@Fuguexv](#):
>
> `repeat thisRecord in theRecord times`

That’s the offending line, this one should work:

```auto
repeat with thisRecord in theRecord

```

---

<div class="post-metadata">

**Author:** ![Fuguexv](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Fuguexv](https://discourse.devontechnologies.com/u/Fuguexv)\
**Post date:** [July 26, 2022, 8:16am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/3 "2022-07-26T08:16:34Z")

</div>

😝Thank you! It did stop reporting errors this time, but it seems that the folder was not opened properly~No corresponding window pops up

---

<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:** [July 26, 2022, 8:18am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/4 "2022-07-26T08:18:41Z")

</div>

You might have to specify the desired database for the `lookup records with comment` command, right now the current database is used which might vary.

---

<div class="post-metadata">

**Author:** ![Fuguexv](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Fuguexv](https://discourse.devontechnologies.com/u/Fuguexv)\
**Post date:** [July 26, 2022, 8:23am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/5 "2022-07-26T08:23:43Z")

</div>

🙏If the name of my Database is “2022AU”, how should I write it?  
I refer to the script written by other users, changed to this seems to be unsuccessful

```auto
tell application id "DNtp"
	set theDatabase to current database
	set theRecord to lookup records with comment taskId in theDatabase
	repeat with thisRecord in theRecord
		open window for record thisRecord
	end repeat
end tell

```

---

<div class="post-metadata">

**Author:** ![Fuguexv](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Fuguexv](https://discourse.devontechnologies.com/u/Fuguexv)\
**Post date:** [July 26, 2022, 8:41am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/6 "2022-07-26T08:41:37Z")

</div>

The problem seems to be that the record indexed by DT does not synchronize the comment information from Finder

 ![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/d/b/db151d1a18a127d54b2f445faa835520dee4b907.png)  
⬆ Finder

 ![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/b/1/b16adc801b86deaacae7e4a8e0c91ed840c451c1.png)  
⬆ DT

---

<div class="post-metadata">

**Author:** ![Blanc](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/blanc/32/8008_2.png) [@Blanc](https://discourse.devontechnologies.com/u/Blanc)\
**Post date:** [July 26, 2022, 8:51am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/7 "2022-07-26T08:51:18Z")

</div>

I can’t confirm that - I have just tested adding a comment using Finder, and it is immediately present in DT. Presumably if you select “Get Info” from the context menu of the file in Finder, that comment is shown under the “Comments:” section?

What happens if you select File \> Update Indexed Items in DT?

---

<div class="post-metadata">

**Author:** ![Fuguexv](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Fuguexv](https://discourse.devontechnologies.com/u/Fuguexv)\
**Post date:** [July 26, 2022, 8:54am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/8 "2022-07-26T08:54:07Z")

</div>

I created a new task and re-ran the script and it seems to work! Thanks for the above reply! Thank you very much!

---

<div class="post-metadata">

**Author:** ![Fuguexv](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Fuguexv](https://discourse.devontechnologies.com/u/Fuguexv)\
**Post date:** [July 28, 2022, 5:30am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/9 "2022-07-28T05:30:38Z")

</div>

Sorry, I’m bumping this thread up again, a new question 😭 If I want this newly opened window to be the currently activated window, what do I need to write in the script?

---

<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:** [July 28, 2022, 6:33am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/10 "2022-07-28T06:33:23Z")

</div>

Here’s a simple demo:

```applescript
tell application id "DNtp"
	set win1 to viewer window 1
	set win2 to open window for record (selected record 1)
	activate win1
end tell

```

---

<div class="post-metadata">

**Author:** ![Fuguexv](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/f/9d8465/32.png) [@Fuguexv](https://discourse.devontechnologies.com/u/Fuguexv)\
**Post date:** [July 28, 2022, 8:37am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/11 "2022-07-28T08:37:43Z")

</div>

thank you!! it works!! ❤

---

<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:** [July 27, 2025, 8:38am UTC](https://discourse.devontechnologies.com/t/how-to-open-record-with-specific-comment/72039/12 "2025-07-27T08:38:43Z")

</div>

Closed on July 27, 2025, 8:38am UTC

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