Previously working AppleScript failing in DT4 beta

As part of a previously working Keyboard Maestro macro, i use the following AppleScript (developed by someone else), which seems not to work in DT4 beta:

set masterList to {}
tell application id "DNtp"
	set allDatabases to every database
	repeat with thisDatabase in allDatabases
		set dbName to name of thisDatabase
		set allGroups to (every record of thisDatabase whose type is group)
		set groupList to {}
		repeat with thisGroup in allGroups
			set groupName to name of thisGroup
			set groupUuid to uuid of thisGroup as string
			if groupName is not in {"Trash", "Tags"} then
				set tempList to groupName & ":" & groupUuid
				if groupList = {} then
					set groupList to tempList
				else
					set groupList to groupList & "
" & tempList
				end if
			end if
		end repeat
		if groupList ≠ {} then
			if masterList = {} then
				set masterList to groupList
			else
				set masterList to masterList & "
" & groupList
			end if
		end if
	end repeat
	--set masterList to "[" & masterList & "]"
end tell
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"
"}
set masterList to masterList as string
set AppleScript's text item delimiters to saveTID
return masterList

ScriptEditor points to the parenthetical portion (every record…) in the sixth line as the culprit:

set allGroups to (every record of thisDatabase whose type is group)

I’ve checked the AppleScript dictionary for DT4, but can’t figure out what, if anything, might have changed in the syntax. The error message is:

error “DEVONthink got an error: Can’t get property list item.” number -1728 from

Thanks for any help.

Development would have to assess this as it works in DEVONthink 3.

The script suite was completely rewritten and although almost all scripts still work due to e.g. lots of synonyms, this is not always the case. Databases do not contain records anymore as this old one-to-many relationship was actually limited to the items of the root of the database, dating back to v1.x and not really useful.

In this case just use…

set allGroups to (parents of thisDatabase whose type is group)

…and this returns indeed all groups of the database. But if you prefer only the groups located in the root of the database, then use…

set allGroups to (children of root of thisDatabase whose type is group)
4 Likes

Excellent - thanks so much!

This helped me fix one error in an AppleScript but running across another now with a previously working script:

children of root of theDatabase whose type is not group and creation date ≥ startDate and creation date ≤ endDate

returns an error:

DEVONthink got an error: Can’t get tiff image.

Adding “type is not image” does not correct that error.

Please post the complete source of the script.

-- we're looking at yesterday since this fires off at 4am
set startDate to date (short date string of ((current date) - 1 * days))
set endDate to date (short date string of ((current date) - 1 * days))
set endDate's hours to 23
set endDate's minutes to 59
set endDate's seconds to 59

set inCount to 0
set outCount to 0
set messCount to 0

tell application id "DNtp"
	-- set destination_database to open database "/Users/jrickmd/Documents/DEVONthink/DEVONthink 2.dtBase2" -- Ensure that the database is open
	set theDatabase to (first database whose name is "Patients")
	
	-- find every record added between dates	
	-- set recordList to (every record of theDatabase whose type is not group and type is not tag group and type is not image and creation date ≥ startDate and creation date ≤ endDate)
	set recordList to (children of root of theDatabase whose type is not group and creation date ≥ startDate and creation date ≤ endDate)
	
	return
	-- set recordList to (every record of theDatabase whose type is not group and type is not tag group and (URL contains "mailto:" or name contains "chat with") and creation date ≥ startDate and creation date ≤ endDate)
	repeat with aRecord in recordList
		if URL of aRecord contains "mailto:drj@md.com" then
			set inCount to inCount + 1
		else if URL of aRecord contains "mailto:" then
			set outCount to outCount + 1
		else if name of aRecord contains "chat with " then
			set messCount to messCount + 1
		end if
	end repeat
end tell

Why do you have an unconditional return statement in the middle your code?

simply stopping the AS so it didn’t continue until I figured out the bug I was getting prior to it…

(I was changing the recordList line above it to figure out what the conditional error was which could have returned far to many results for the following repeat)… but could never get past the simple “every record whose type is not group” without an error.

Other people are not more qualified to talk about AppleScript code. I’d try to use more parenthesis, I guess. And of course run the code in script editor to see what data is send forwards and backwards.

Why not this…

set inCount to 0
set outCount to 0
set messCount to 0

tell application id "DNtp"
	set theDatabase to database "Patients"
	
	repeat with theScope in {incoming group of theDatabase, root of theDatabase}
		set theSearch to (search "added:yesterday {any: url:mailto name:\"chat with\"} {kind:!group kind:!smartgroup}" in theScope)
		if theSearch is not {} then
			repeat with aRecord in theSearch
				if URL of aRecord contains "mailto:drj@md.com" then
					set inCount to inCount + 1
				else if URL of aRecord contains "mailto:" then
					set outCount to outCount + 1
				else if name of aRecord contains "chat with " then
					set messCount to messCount + 1
				end if
			end repeat
		end if
	end repeat
	return {inCount, outCount, messCount}
end tell
1 Like

I will certainly try it when I get home… (still on 3.x at work)

I have been programming in AS for decades and always love that every time I post a script and see someone’s altered script it makes mine look infantile. :rofl:

Rick

Haha! I know the feeling for sure, even with my own code in hindsight.

Success.

Looks like using “search” as an AS means of getting a set of records might be a more inter-version stable mechanism. Maybe?

So far, the other scripts I’ve updated have done well by changing the “every record of thisDatabase whose…” to “children of root of thisDatabase whose…”. But I’m having to put a

try
   -- 4.0 beta use children of root

on error
   -- 3.x use every record of

end try

block to cover my bases for now.

Not sure why this specific one didn’t work. But glad it’s working now. Thanks again.

Rick

You’re welcome.
In DEVONthink 4 bear in mind, children belong to a parent. contents belong to a database, though it’s a broader term and includes all documents and non-documents.

1 Like

contents of a database are actually only documents, parents of a database include (smart) groups, feeds and tags. And likewise parents of a record are groups, feeds and/or tags.

Did this change from beta 2? I could have sworn I was getting groups with contents as well.

No. It’s the same since DEVONthink Pro 1.x.

If I may jump into this (I can’t test the beta currently and don’t want to deploy it in production): I have a script that pulls stuff from Zotero and creates a pretty complex data structure in one of my databases. It makes extensive use of:

get record at path in database
create record with … in database
get record with uuid in database
replicate record

Will all this stop working? Is there an easy substitute for each of those?

All these commands still exist. If it’s AppleScript, then chances are pretty good that it still works without any changes if it’s using tell application id "DNtp" instead of tell application "DEVONthink 3"