Changing active database

I am trying to do essentially the same thing as “adad” in this post: ([url]How to change which database is "active" in a script]), that is, ensure the right database is open when running Sampsa’s tickler file script (no. 2 here: [url]Scripts for a Tickler File]).

Applying the corrections suggested by Korm, I am trying to run the script below, but if another database is open in DT the actions happen there. ```
property FOLDERS_MONTHS : {“01 January”, “02 February”, “03 March”, “04 April”, “05 May”, “06 June”, “07 July”, “08 August”, “09 September”, “10 October”, “11 November”, “12 December”}
property FOLDERS_DAYS : {“01”, “02”, “03”, “04”, “05”, “06”, “07”, “08”, “09”, “10”, “11”, “12”, “13”, “14”, “15”, “16”, “17”, “18”, “19”, “20”, “21”, “22”, “23”, “24”, “25”, “26”, “27”, “28”, “29”, “30”, “31”}

tell application “DEVONthink Pro”
activate
set myDB to database “Daily”
tell database myDB
activate
set todayFolder to create location “/* Inbox”
set ticklerFolder to “/** Tickler”
set currentMonth to item (month of (current date)) of FOLDERS_MONTHS
set currentDay to item (day of (current date)) of FOLDERS_DAYS
set currentFolder to create location (ticklerFolder & “/” & currentMonth & “/” & currentDay)
set theChildren to the children of currentFolder
repeat with theRecord in theChildren
move record theRecord to todayFolder
end repeat
end tell
end tell


None of the other suggestions made work either, e.g., specifying the database for each action as follows:

set todayFolder to create location “/* Next Actions” in database “Daily”


I've tried simplifying the script (as below), just to switch to another database, with variations on the details for the path, but I consistently get the error "missing value" for the database, so I suspect this is where the problem lies.

tell application “DEVONthink Pro”
activate
set myDB to open database “Daily”
tell database myDB
activate
end tell
end tell


tell application “DEVONthink Pro”
activate
set myDB to open database “~/Documents/DevonThink/Daily”
tell database myDB
activate
end tell
end tell


Only this script:

tell application “DEVONthink Pro”
activate
set myDB to open database “~/Documents/DevonThink/Daily.dtBase2”
tell database myDB
activate
end tell
end tell


returns the reply --> database id 2

but changing the path this way in the first script just returns another error:

"DEVONthink Pro got an error: Can’t get database \"~/Documents/DevonThink/Daily.dtBase2\".

I'd be grateful for any advice!

This works over here. Adjust


set myDB to open database "~/Documents/DEVONthink Databases/Test 20130323 Renamed.dtBase2"

to your own path.

The full working model:

-- Maintain a Tickler Folder
-- Revised from ideas developed by @will from ideas developed by @adad, @Sampsa
-- 20131031
-- v01 see https://discourse.devontechnologies.com/t/changing-active-database/16579/1

property FOLDERS_MONTHS : {"01 January", "02 February", "03 March", "04 April", "05 May", "06 June", "07 July", "08 August", "09 September", "10 October", "11 November", "12 December"}
property FOLDERS_DAYS : {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}

tell application "DEVONthink Pro"
	
	-- set path to your personal database path
	set myDB to open database "~/Documents/DEVONthink Databases/Test 20130323 Renamed.dtBase2"
	
	set currentMonth to item (month of (current date)) of FOLDERS_MONTHS
	set currentDay to item (day of (current date)) of FOLDERS_DAYS
	
	set todayFolderName to "/*Inbox"
	set ticklerFolderName to "/**Tickler"
	set currentFolderName to ticklerFolderName & "/" & currentMonth & "/" & currentDay
	
	set todayFolder to create location todayFolderName in myDB
	set ticklerFolder to create location ticklerFolderName in myDB
	set currentFolder to create location currentFolderName in myDB
	
	try
		set theChildren to the children of currentFolder
		if theChildren is {} then error "Current Folder has no Children"
		
		repeat with theRecord in theChildren
			move record theRecord to todayFolder
		end repeat
	on error errorMessage
		display dialog errorMessage
	end try
	
end tell

  1. Organized the code in logical blocks
  2. Added error checking
  3. Need to use the structure "set THIS to create location THAT in database THEDATABASE
  4. Cannot use quoted strings in “create”; need to use variables, which are set early in the script

Many thanks - this works here too, with one small modification to the folder names defined originally (by Sampsa) which include spaces after the asterisks “/* Inbox” and “/** Tickler” (so if you used his script to set up your Tickler file, you’ll need to modify the names in the file, or in this script.

But many thanks - I’m so pleased I no longer have to make sure I leave DevonThink in the right database overnight when this script runs! :smiley: