How to open Record with specific comment

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

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

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

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

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

repeat with thisRecord in theRecord

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

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.

:pray: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

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

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


:arrow_up: Finder


:arrow_up: DT

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?

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

1 Like

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

Here’s a simple demo:

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

thank you!! it works!! :heart: