I am searching on a database for returns as PDFs and webarchives. I have the Applescript below. It works for my initial needs. Next, I want to copy out a list of results to paste elsewhere. I want to have hyperlinks in the list. How do I get theURL to be an active hyperlink, either to the webarchive (global) or to the PDF file (local)?
(I’ve commented out portions that were for testing)
on run
set theList to ""
tell application id "com.devon-technologies.thinkpro2"
set theSelection to selection
repeat with thisItem in theSelection
set theName to the name of thisItem
if (the URL of thisItem is "") then
set theURL to ("file:/" & the path of thisItem)
else
set theURL to (the URL of thisItem)
--set theURL to (do shell script "php -r 'echo urlencode(\"" & theURL & "\");'")
-- set theURL to "<a href='" & theURL & "'>" & theName & "</a>"
end if
set theList to theList & theName & " - " & theURL & return
end repeat
set the clipboard to theList
end tell
theList
end run
(pps – can a post be moved to a different category after it is posted???)
Since you didn’t specify format, I’ll assume you want the link to be rich text. Here is the basic technique I use (to put links in RTF format on the clipboard):
set v_HTML to quoted form of ("<font face=\"helvetica\"><a href=\"" & v_URL & "\">" & v_Text & "</a></font>")
do shell script "echo " & v_HTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
The operative piece is packing the URL into an HTML string and then using textutil to convert that to RTF on the clipboard.
You could
set v_Link to the clipboard
This will come out as “class RTF” content in the variable. Build up an RTF document with v_Link
By the way, your code for PDFs is potentially creating a “file://” link directly into a database package. That’s generally considered unsafe coding. And unreliable, because if DEVONthink reorganizes a database behind the scenes, or a future release of DEVONthink changes the internal folder structure of your database package, then the link will cease working. Consider using the “reference URL” instead – which is the x-devonthink-item:// form.
@korm: Since you didn’t specify format, I’ll assume you want the link to be rich text. …
Likely yes. I’ll play around with what you show.
As to the file:// links … they point to the source database not the DTP database. IOW, they all start as /Users/jjw/Documents/…/Library.papers3/… I prefer this rather than linking the PDFs back to DTP. Since they are PDFs, I can then opt to open them directly in PDF Expert.
(also, I INDEX the library using DTP so AFAIK this should not change its structure … although I know that other apps might … but I’ll live with this for now because all I want is something to paste in to … Curio)