I wanted to move records after sync to a database’s incoming group and close the database if it wasn’t open before the script opened it. There seems to be a bug with database references.
-
My first approach was opening the database and getting its
incoming group
.
It does work if the Smart Rule is triggered manually. It doesn’t work if used as an embedded or an external script with triggerAfter Synchronization
, the database opens but the script seems to fail to get theincoming group
. There’s no specific error reported, just„DEVONthink 3“ hat einen Fehler erhalten: AppleEvent lieferte eine Zeitüberschreitung.
-
My second approach was to get the
incoming group
withget record at
. This too doesn’t work in an embedded or an external script, same error message. -
My third approach was
get record with uuid
and that works.
Although I don’t need to explicitly open the database when using get record with uuid
I investigated further and these two lines don’t seem to result in a valid database reference:
- This one doesn’t throw an error but using
close theDatabase
at the end doesn’t close the database:set theDatabase to database theDatabaseName
- This one opens the database but throws the error mentioned above:
set theDatabase to open database theDatabasePath
-- Move records after sync and close destination database
property theDatabasePath : "/Users/USER/Documents/DEVONthink/DEVONthink Datenbanken/Datenbanken/test twitter.dtBase2"
property theDatabaseName : "test twitter"
on performSmartRule(theRecords)
tell application id "DNtp"
try
set theOpenDatabaseNames to name of databases
if theOpenDatabaseNames contains theDatabaseName then
set closeDatabase to false
set theDatabase to database theDatabaseName
else
set closeDatabase to true
set theDatabase to open database theDatabasePath
end if
#set theGroup to incoming group of theDatabase
--> „DEVONthink 3“ hat einen Fehler erhalten: AppleEvent lieferte eine Zeitüberschreitung.
#set theGroup to get record at "/Eingang" in theDatabase
--> „DEVONthink 3“ hat einen Fehler erhalten: AppleEvent lieferte eine Zeitüberschreitung.
set theGroup to (get record with uuid "8F3AE377-221F-47C7-A06A-B8098A1CD6E5")
--> works
repeat with thisRecord in theRecords
move record thisRecord to theGroup
end repeat
if closeDatabase = true then
delay 2
#close theDatabase
close (database of theGroup)
end if
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
end performSmartRule