I’m looking for a way to automatically close a specific database if it hasn’t been used recently using DT3’s automation/scripting tools.
I actually have a (seemingly) working script:
tell application id "DNtp"
set theDatabase to get database with uuid "ADB9D9D0-0304-43F4-A187-945F15A4777C"
set theRoot to the root of theDatabase
set lastCreatedDate to theRoot's creation date -- for whatever reason, the created date is updated whenever the database is opened again, which works for my purposes.
-- display dialog lastCreatedDate as string -- for debugging
set timeSinceModification to (current date) - (lastCreatedDate)
-- display dialog timeSinceModification -- for debugging
if timeSinceModification is greater than 300 then
close theDatabase
end if
end tell
I realize that I can run this from a cronjob or Keyboard Maestro, but is there a way to link it to a Smart Rule? The trick is that it doesn’t really depend on any records that could be picked up by the Smart Rule.