The ‘Open in external editor or viewer’ button is useful, but I find that I regularly work with two or three different applications for the same record type.
The sheer length of Open With lists, on the other hand, proves irritating after a while …
Any solutions ?
(For the moment, I am experimenting with a simple script which offers me just WriteRoom, OmniOutliner, TextMate or Marked for a selected TXT record, Skim or Acrobat Pro for a PDF record, and so forth. Additional types/apps can be added quite easily).
-- TEXT: WriteRoom, OmniOutliner, TextMate, or Marked
-- PDF: Skim or Adobe Acrobat Pro
-- oo3: OmniOutliner or OmniGraffle
property plstTypes : {¬
{"Text", "WrRm", "OOut", "TxMt", "com.brettterpstra.marky"}, ¬
{"PDF", "SKim", "CARO"}, ¬
{"oo3", "OOut", "OGfl"}}
-- Either come in with no preference info, and throw up a menu
-- or come in with a letter, bypass the menu, and find the first option which has that letter in the earlier place
on handle_string(strSubString)
ReachForApp(strSubString)
end handle_string
on run
ReachForApp("")
end run
on ReachForApp(strSubString)
tell application id "DNtp"
activate
-- IS A DEVONTHINK RECORD SELECTED ?
tell content record
if it is missing value then return
set strPath to (its path) as Unicode text
if strPath = "" then return
set strKind to kind
end tell
-- ARE THERE ANY PREFERRED APPLICATIONS FOR THIS KIND OF RECORD ?
set lstAppNames to {}
repeat with oKind in plstTypes
if strKind starts with first item of oKind then
repeat with oApp in (items 2 thru -1 of oKind)
set end of lstAppNames to name of my application id oApp
end repeat
exit repeat
end if
end repeat
-- IF NOT, THEN OPEN WITH THE DEFAULT APPLICATION
if (count of lstAppNames) < 1 then
do shell script "open " & quoted form of strPath
else
set blnFound to false
if strSubString ≠ "" then
set strMatches to ""
repeat with oName in lstAppNames
set strMatches to strMatches & my PatternMatch(oName, strSubString, true) & " " & oName & linefeed
end repeat
set lstSorted to paragraphs of texts 2 thru -1 of (do shell script "echo " & quoted form of (strMatches) & " | sort -n -k 1")
set {dlm, my text item delimiters} to {my text item delimiters, " "}
repeat with oLine in lstSorted
set {strWhere, strApp} to text items of oLine
if strWhere ≠ "0" then
set blnFound to true
exit repeat
end if
end repeat
set my text item delimiters to dlm
end if
if not blnFound then
-- OFFER THE USER A CHOICE,
tell application id "sevs"
activate
set varChoice to choose from list lstAppNames default items first item of lstAppNames with prompt "Application:" with title "Open with ..."
end tell
if varChoice is false then return
set strApp to first item of varChoice
end if
-- AND OPEN WITH THE CHOSEN APPLICATON
do shell script "open -a " & quoted form of strApp & space & quoted form of strPath
end if
end tell
end ReachForApp
(* Returns position of last character of matched pattern *)
on PatternMatch(strText, strPattern, blnIgnoreCase)
set strIgnore to ""
if blnIgnoreCase then set strIgnore to "i"
try
(do shell script "echo " & quoted form of strText & " | perl -ne 'if (m/(" & strPattern & ")/" & strIgnore & ") {print \"$+[1]\"}'") as integer
on error
0
end try
end PatternMatch