Updated for DEVONthink 3
-- Open last added record (DEVONthink 3)
property alwaysOpenInDocumentWindow : true
tell application id "DNtp"
try
set currDate to current date
set theComparisonDate to currDate - 86400 -- 24 hours
set theDatabases to databases
repeat with thisDatabase in theDatabases
set thisDatabasesResults to search "additionDate >" & theComparisonDate in (root of thisDatabase)
if thisDatabasesResults ≠ {} then
set thisDatabasesLastAdded to item -1 of thisDatabasesResults
if (addition date of thisDatabasesLastAdded) ≥ theComparisonDate then
set theComparisonDate to (addition date of thisDatabasesLastAdded)
set globalLastAdded to thisDatabasesLastAdded
end if
end if
end repeat
if alwaysOpenInDocumentWindow = true then
set theDocWins to every document window
repeat with thisDocWin in theDocWins
if content record of thisDocWin = globalLastAdded then
set thisDocsIndex to index of thisDocWin
tell application "System Events" to tell process "DEVONthink 3"
perform action "AXRaise" of window thisDocsIndex
end tell
activate
return
end if
end repeat
open tab for record globalLastAdded
activate
else
open window for record globalLastAdded
activate
end if
on error error_message number error_number
if the error_number is not -128 then
display alert "DEVONthink 3" & space & error_number message error_message as warning
end if
end try
end tell