Automatically close a database

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.

When I want to do a periodic task not related to anything specific, I create an empty text file, name it as the task I want to do (to know this empty document is associated to that task), enable a periodic reminder and then associate the script to it.

I even paste the script into the txt document body to have it located just in case I disable or remove the associated script.

1 Like

@rfog’s suggestion is a useful one.

1 Like

Ah, of course, a reminder! I knew there was something obvious I wasn’t thinking of.

Thanks!