I played around a bit with the Daily Backup Archive script to automatize it and it did work quite well with one exception: The script does only affect the database selected in the moment he script gets active.
When I am in my main database the script saves it like intended. But when I happen to have selected, say, the Global Inbox, then the Global Inbox is saved. Which is not intended.
Or to put in in Apple Script: How can I change
set this_database to current database
to
set this_database to *database X*
?
I tried its name and its x-devonthink-item link but neither worked. Which might be due to wrong syntax.
Is it possible at all to select a specific database per Apple Script?
To select a database? A selection is a very specific thing and it is something that should be reserved for very specific things, i.e., rarely used in general scripting.
However, yes you can talk directly to a database. You need to quote the database’s name (and no, the extension isn’t required. @rfog needed it because he was opening a file, which does require the full filename).
Here is a small teaching edition example, with a check for the database included…
tell application id "DNtp"
if (exists database "Temp") then
-- This checks is the database is OPEN, not if it actually exists in the filesystem.
-- It's saying, does this database "exist to DEVONthink right now")
set DB to database "Temp"
-- Do stuff…
else
-- Don't do stuff… or do other stuff.
end if
end tell
If you want to make things a bit more flexible (or complicated, depending on your point of view), you might also do this to choose from a list of open databases:
tell application id "DNtp"
set theDBs to (get name of every database)
set this_database to database (item 1 of (choose from list theDBs))
end tell
and then do whatever you wish with the variable this_database.
I had definitely tried this before amongst others. And why didn’t it work then? Because DEVONthink seems to cache the external script while running and therefore did not use the updated script. But after quitting DT and starting it again it works with the new version of the script.
And now it works just fine. I got a reminder with a script in a database to regularly backup that database as ZIP. I tried a Smart Rule at first but the Reminder allows me a specific date and time opposed to “hourly”, “daily”, etc. in the Smart Rule.
I was referring to selecting a database (or one of its groups or files) in DT’s leftmost panel which is a most common thing. Just a confusion of nomenclature I guess.