Alfred 2 is out of beta, and offers some interesting features that play well with DEVONthink. For example, this recently posted Alfred workflow from @Nebelleuchte kicks off a DEVONthink search from the Alfred window. This is a basic example of integration with DEVONthink – since Alfred workflows can execute AppleScripts, much more complex actions are possible. Another very nice example of this was posted here a while back by @danielsh
I’ve been working with Alfred 2 all day. Thanks for sharing that link.
Alfred workflows for DTPO are very limited.
I’d like to have this applescript work with Alfred. Can anybody help?
Alfred 2 supports Applescript. Anything you can do in DTPO with AppleScript you can add as a Alfred 2 Workflow. The script you linked to however, when I tried to open it in AppleScript Editor it won’t open like other .scpt files. Otherwise, it would be as simple as copy/paste into an Alfred Workflow.
If you can get the author to post the script as a .txt file, you can then copy and paste into Alfred 2. The script does run in DTPO 2, but I wasn’t able to edit it in the AppleScript Editor.
Here is the script as txt. it is meant for LaunchBar to work like this "The default verb (Move) can be overridden by prefixing the search string with "d " or “r " (for “Duplicate” or “Replicate”) in LaunchBar or the standard dialog (a single verb letter followed by a single space before the search”.
how can this be implemented in Alfred?
property pMove : "Move"
property pDup : "Duplicate"
property pRep : "Replicate"
property pDefaultVerb : pRep -- Default verb: may be switched to Duplicate (pDup) or Replicate (pRep) at run-time
-- ver 1.0 Allows double dot (..) as short-hand for parent group
-- (to facilitate moving selected records up one level in the group hierarchy)
-- ver 0.9 Fixed a big involving search strings which include a space
-- ver 0.8 Clarified the Growl message: bold header: [Verb]d [N] records to:, body:[Destination]/n[List of records]
-- ver 0.7 Enhanced the "Group not Found" message for replication to remind user that replication
-- is only possible within a single database.
-- ver 0.6 The default verb (Move) can be overridden by prefixing the search string with "d " or "r "
-- (for "Duplicate" or "Replicate") in LaunchBar or the standard dialog
-- (a single verb letter followed by a single space before the search string itself)
-- ver 0.5 Can get the search string from LaunchBar
-- ver 0.4 Allows target databases (where their names match) as well as target folders
-- (the default incoming group of the database is used as the destination)
property pVer : "1.0"
property pTitle : " to target group" & " " & pVer
property pstrDelim : " "
on run
set lstSelns to GetDevnSelns()
if lstSelns ≠ {} then
set strNames to GetNameList(lstSelns)
set strCmd to GetSearchString(pDefaultVerb, strNames)
if strCmd ≠ "" then
set {strVerb, strFind} to ParseCmd(strCmd)
if strFind ≠ "" then ProcessSelns(lstSelns, strNames, strVerb, strFind)
end if
end if
end run
-- GET THE TARGET GROUP SEARCH STRING FROM LAUNCHBAR
on handle_string(strCmd)
if strCmd ≠ "" then
set lstSelns to GetDevnSelns()
if lstSelns ≠ {} then
set {strVerb, strFind} to ParseCmd(strCmd)
if strFind ≠ "" then
set strNames to GetNameList(lstSelns)
ProcessSelns(lstSelns, strNames, strVerb, strFind)
end if
end if
end if
end handle_string
on ParseCmd(strCmd)
set {strVerb, strFind} to {pDefaultVerb, ""}
set text item delimiters to space
set lstParts to text items of strCmd
if length of lstParts > 1 then
set strFirst to first item of lstParts
ignoring case
if strFirst is in {"m", "d", "r"} then
if strFirst = "m" then
set strVerb to pMove
else if strFirst = "d" then
set strVerb to pDup
else if strFirst = "r" then
set strVerb to pRep
end if
set strFind to (items 2 thru end of lstParts) as string
else
set strFind to strCmd
end if
end ignoring
else
set strFind to strCmd
end if
{strVerb, strFind}
end ParseCmd
on ProcessSelns(lstSelns, strNames, strVerb, strFind)
-- CHECK THAT A KNOWN VERB IS SPECIFIED AT THE TOP OF THE SCRIPT
if strVerb is not in {pMove, pDup, pRep} then
tell application id "com.apple.systemevents"
activate
display dialog "\"" & strVerb & "\": unknown value for pDefaultVerb" & return & return & "Expected Move | Duplicate | Replicate"
end tell
return
end if
tell application id "com.devon-technologies.thinkpro2"
-- GET FILTERED SET OF POSSIBLE DESTINATIONS
if strVerb ≠ pRep then
-- BOTH OPEN DATABASES WITH MATCHING NAMES
set lstParent to (incoming group of databases where name contains strFind)
-- AND FOLDERS WITH MATCHING NAMES
repeat with oDb in databases
set lstParent to lstParent & (parents of oDb where name contains strFind)
end repeat
else -- OR, IN THE CASE OF REPLICATION, IN CURRENT DATABASE
set lstParent to (parents of current database where name contains strFind)
end if
-- ALLOW FOR DOUBLE DOT (..) AS REFERENCE TO PARENT DIRECTORY OF SELECTED ITEMS
if strFind = ".." then set end of lstParent to first item of parents of (first item of lstSelns)
-- BUILD NUMBERED MENU OF DESTINATION NAMES
set lngParents to length of lstParent
if lngParents > 0 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 strVerb & pTitle with prompt strVerb & ":
" & strNames & "
to target group:" 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
-- MOVE | DUPLICATE | REPLICATE SELECTED ITEMS TO DESTINATION
if strVerb = pMove then
repeat with oRec in lstSelns
move record oRec to oTarget
end repeat
else if strVerb = pDup then
repeat with oRec in lstSelns
duplicate record oRec to oTarget
end repeat
else if strVerb = pRep then
repeat with oRec in lstSelns
replicate record oRec to oTarget
end repeat
end if
-- NOTIFY RESULT BY GROWL (IF INSTALLED) OR WITH DIALOG BOX
my Announce(oTarget, strVerb, (length of lstSelns), strNames)
tell application id "com.devon-technologies.thinkpro2"
open window for record oTarget
activate
end tell
end if
else
if strVerb ≠ pRep then
set strRepNote to ""
else
set strRepNote to "
(If you were attempting to replicate to another open database, note that DevonThink only supports replication within a single database)"
end if
tell application id "com.apple.systemevents"
activate
display dialog "No open groups contain the string:" & "
" & strFind & strRepNote buttons {"OK"} default button "OK" with title strVerb & pTitle
end tell
end if
end tell
end ProcessSelns
on GetDevnSelns()
tell application id "com.devon-technologies.thinkpro2"
return selection
end tell
end GetDevnSelns
on GetSearchString(strVerb, strNames)
set strFind to ""
-- GET SUB-STRING TO FILTER LIST OF TARGETS
tell application id "com.apple.systemevents"
activate
set strFind to text returned of (display dialog strVerb & ":" & return & return & strNames & return & ¬
"Enter search string to list target groups:" default answer "" buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel" with title strVerb & pTitle)
end tell
return strFind
end GetSearchString
on GetNameList(lstSelns)
-- BUILD BULLETED LIST OF SELECTION NAMES
set strNames to ""
repeat with i from 1 to count of lstSelns
set strNames to strNames & "• " & name of (item i of lstSelns) & return
end repeat
return strNames
end GetNameList
-- REPORT RESULT
on Announce(oGroup, strVerb, lngRecords, strNames)
tell application id "com.devon-technologies.thinkpro2" to set {strDb, strPath, strFolder} to {name of database, location, name} of oGroup
set strGrowlTitle to strVerb & "d " & (lngRecords as string) & " records to:"
set strGrowlBody to strDb & strPath & strFolder & "
" & strNames
tell application id "com.apple.systemevents"
--USE GROWL IF IT'S RUNNING
if (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0 then
tell application id "com.Growl.GrowlHelperApp"
register as application "houthakker scripts" all notifications {pTitle} default notifications {pTitle} icon of application "DEVONthink Pro"
notify with name pTitle title strGrowlTitle application name "houthakker scripts" description strGrowlBody
end tell
else
-- (OR USE A STANDARD DIALOG)
--tell application id "com.apple.systemevents"
--activate
--display dialog strReport & "
--(This script works best if Growl is installed)" buttons {"OK"} with title pTitle
--end tell
end if
end tell
end Announce
-- 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
Any news on this? Would be very useful but I’m not on the scripting side !