With more than one open (and fairly complex) database, finding and opening a particular group can be slower and a bit more mouse-infested than it should be
Edit > Find > In Database is a workable route, but unless you have already selected the target database you wonāt get a hit from your search-string at all, and you still have to dbl-click the group if it does show up in the match list (even, in fact, if itās the only match).
Do tell me if I am missing a quicker route. In the meanwhile, I have attached a key-stroke to the script below, which:
- Needs no mice,
- Searches across all open databases,
- Jumps straight to the target folder if there is a unique match for the string you have typed,
- Offers a full-path list of matching groups if there is more than one.
- Can get its search string from LaunchBar
- [EDIT - as of Ver 0.4, see posts below, can use LaunchBarās Instant Send mode to copy files from the Finder straight to a group in DT]
- [EDIT2 - as of Ver 0.5, if selected text picked up by LaunchBar Instant Send is a URL rather than part of a group name, the user is prompted for a group, and a bookmark for the URL is created in the target group]
property pVer : "0.6"
property pTitle : "Go to DT group" & " " & pVer
property pstrDelim : " "
-- Ver 0.6 Small fixes to standardize alert when no match is found.
-- Ver 0.5 If text selected by LaunchBar Instant Send matches no group and appears to be a URL,
-- then make a BookMark record for this URL in the target group
-- Ver 0.4 Can use LaunchBar 'Instant Send' to copy files selected in Finder straight to target DT group
-- Ver 0.3 Avoids opening additional windows for the same group - checks for existing windows for target group before creating a new one
-- Ver 0.2 Can get its search string from Launchbar
-- SEARCH FOR DT GROUP BY STRING PASSED TO LAUNCHBAR
on handle_string(strText)
if strText ā "" then
set lstMatches to GetMatches(strText)
if lstMatches ā {} then
OpenGroup(lstMatches)
else if isURL(strText) then -- IF THERE IS NO MATCHING GROUP, AND THE STRING LOOKS LIKE A URL, PROMPT FOR GROUP AND MAKE A BOOKMARK
set strFind to GetSearchString()
if strFind ā "" then
set lstMatches to GetMatches(strFind)
if lstMatches ā {} then
set oTarget to OpenGroup(lstMatches)
if oTarget is not missing value then
tell application id "com.devon-technologies.thinkpro2"
set oRec to (create record with {name:strText, type:bookmark, URL:strText} in oTarget)
end tell
end if
else
WarnNotFound(strFind)
end if
end if
else
WarnNotFound(strText)
end if
end if
end handle_string
-- COPY FILES SELECTED WITH LAUNCHBAR INSTANT SEND TO TARGET GROUP
on open lstArgv
if class of lstArgv is list and lstArgv ā {} then
-- PROMPT USER FOR SEARCH STRING (TO IDENTIFY TARGET GROUP)
set strFind to GetSearchString()
-- COPY FILES TO THE USER'S CHOICE OF TARGET GROUP
if strFind ā "" then
set lstMatches to GetMatches(strFind)
if lstMatches ā {} then
set oTarget to OpenGroup(lstMatches)
if oTarget is not missing value then
tell application id "com.devon-technologies.thinkpro2"
repeat with oFile in lstArgv
import (POSIX path of oFile) to oTarget
end repeat
activate
end tell
end if
else
WarnNotFound(strFind)
end if
end if
end if
end open
-- SIMPLE USE (WITHOUT LAUNCHBAR) PROMPT USER FOR SEARCH STRING AND OPEN CHOSEN GROUP
on run
set strFind to GetSearchString()
if strFind ā "" then
set lstMatches to GetMatches(strFind)
if lstMatches ā {} then
OpenGroup(lstMatches)
else
WarnNotFound(strFind)
end if
end if
end run
on GetMatches(strFind)
tell application id "com.devon-technologies.thinkpro2"
-- GET FILTERED SET OF POSSIBLE DESTINATIONS
-- BOTH OPEN DATABASES WITH MATCHING NAMES
set lstMatches to (root of databases where name contains strFind)
-- AND FOLDERS WITH MATCHING NAMES
repeat with oDb in databases
set lstMatches to lstMatches & (parents of oDb where name contains strFind)
end repeat
end tell
lstMatches
end GetMatches
on OpenGroup(lstParent)
set oTarget to missing value
tell application id "com.devon-technologies.thinkpro2"
-- BUILD NUMBERED MENU OF DESTINATION NAMES
set lngParents to length of lstParent
if lngParents > 0 then
if lngParents > 1 then
set lngDigits to length of (lngParents as string)
set lstMenu to {}
repeat with i from 1 to lngParents
tell item i of lstParent
set strName to (name of its database) & its location & its name
end tell
if strName = "Inbox/Inbox" then set strName to "Global Inbox"
set end of lstMenu to my PadNum(i, lngDigits) & pstrDelim & strName
end repeat
-- CHOOSE DESTINATION
tell application id "com.apple.systemevents"
activate
set varTargets to choose from list lstMenu with title pTitle with prompt "Go to:" default items {first item of lstMenu} without multiple selections allowed
end tell
if varTargets is not false then
-- RETRIEVE CHOSEN DESTINATION BY NUMERIC INDEX
set my text item delimiters to space
set oTarget to item ((first text item of (first item of varTargets)) as integer) of lstParent
-- OPEN DT WINDOW FOR TARGET
set lstWins to viewer windows where root is oTarget
if length of lstWins > 1 then
open first item of lstWins
else
open window for record oTarget
end if
end if
else
set oTarget to (first item of lstParent)
set lstWins to viewer windows where root is oTarget
if length of lstWins > 1 then
open first item of lstWins
else
open window for record oTarget
end if
end if
activate
end if
end tell
return oTarget
end OpenGroup
on WarnNotFound(strText)
tell application id "com.apple.systemevents"
activate
display dialog "No open Devonthink groups contain the string:" & "
" & strText buttons {"OK"} default button "OK" with title pTitle
end tell
end WarnNotFound
on GetSearchString()
set strFind to ""
-- GET SEARCH STRING FROM USER
tell application id "com.apple.systemevents"
activate
set strFind to text returned of (display dialog "Enter search string to find target group:" default answer "" with title pTitle)
end tell
return strFind
end GetSearchString
on isURL(str)
return (str contains "://")
end isURL
-- GET A DIGIT STRING OF MINIMUM WIDTH (LEFT-PADDING WITH ZEROS WHERE NEEDED)
on PadNum(lngNum, lngDigits)
set strNum to lngNum as string
set lngGap to (lngDigits - (length of strNum))
repeat while lngGap > 0
set strNum to "0" & strNum
set lngGap to lngGap - 1
end repeat
strNum
end PadNum