Hi, recently I made two Smart Rule (scripts) that closed all databases that were opened due to syncing:
-
One that writes all open database names into a text file
Event:Before Synchronization
-
One that closes all databases whose name is not included in the text file
Event:After Synchronization
This worked fine while testing and also in practice. However now it doesn’t work at all anymore. Already restarted DTTG, DEVONthink, iPhone and Mac.
After spending far too much time with this I tested how often a Smart Rule with event Before Synchronization
is actually triggered:
- with 5 synced databases (including the global inbox) the below script reveals that the Smart Rule is triggered 10 times.
What’s that?
-- Write count of Smart Rule executions into plist
property thePlist_Path : "/Users/USER/Desktop/Triggered_Count.plist"
on performSmartRule()
tell application "System Events"
try
try
exists POSIX file ((thePlist_Path) as string) as alias
tell property list file (thePlist_Path as string)
set theTriggered_Count to value of property list item "Triggered_Count"
set theTriggered_Count_new to theTriggered_Count + 1
set value of property list item "Triggered_Count" to theTriggered_Count_new
end tell
on error
try
make new property list file with properties {name:(thePlist_Path) as string}
tell property list file (thePlist_Path as string)
set theTriggered_Count to 0
make new property list item at end of property list items of contents with properties {kind:integer, name:"Triggered_Count", value:theTriggered_Count}
set theTriggered_Count_new to theTriggered_Count + 1
set value of property list item "Triggered_Count" to theTriggered_Count_new
end tell
on error error_message number error_number
if the error_number is not -128 then display alert "System Events" message error_message as warning
return
end try
end try
on error error_message number error_number
if the error_number is not -128 then display alert "System Events" message error_message as warning
return
end try
end tell
end performSmartRule
But the main problem in case of my initial Smart Rules seems to be that now event Before Synchronization
isn’t triggered before the sync anymore. Writing all opened databases’ names into the text file used to include all open databases before a given synced database was opened (i.e. the synced database name didn’t show up it the text file). Now synced databases are included. As I wrote the scripts after the last DEVONthink update I guess it could be a race condition.