In reponse to a request in another forum, this script creates an HTML index of a selection of documents. The index can be used in a web site, exported, etc.
The script prompts whether you want to use DTPO custom URLs (x-devonthink://) or the URL property defined for that document. In the case where URL properties is the chosen format, if a document does not have an URL property, then it is skipped. If custom URLs is the chosen format there will always be a record because there is always a custom URL for each DTPO document.
-- Made by korm
-- Create HTML index for selected items
-- Prompts whether to creates links using x-devonthink:// custom url
-- or use the URL defined for that document
-- if no URL property is defined, the document is skipped
-- Based on earlier work posted by Christian
set base_name to do shell script "date -n +%Y%m%d\\ %H.%M.%S"
set short_base_name to do shell script "date -n +%Y%m%d"
tell application id "com.devon-technologies.thinkpro2"
try
try
set customURL to true
set dialogAnswer to display dialog ¬
"Use Custom URL" buttons {"Yes", "No"} default button "Yes"
if button returned of dialogAnswer is "Yes" then
set customURL to true
else
set customURL to false
end if
end try
set theSelection to the selection
if theSelection is {} then error "Please select some items."
set theIndex to "<!DOCTYPE html PUBLIC \"-//W3C/DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<html xmlns=\"http://www.w3.org/1999/xhmtl\" xml:lang=\"EN\" lang=\"EN\">
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />
<title>To Read - Current</title>
<style>
a:hover {
text-decoration: none !important;
}
a:visited {
text-decoration: none;
}
a:focus {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:link {
text-decoration: none;
color: black;
font-family: \"Helvetica Neue\", Arial, Helvetica, Geneva, sans-serif;
}
</style>
</head>
<body>" & return
repeat with theRecord in theSelection
if customURL then
set this_link to ("x-devonthink-item://" & uuid of theRecord as string)
else
set this_link to (URL of theRecord as string)
end if
-- skip records that do not have URLs if the option to use custom URLs is FALSE
if not customURL then
if (URL of theRecord) is not "" then
set theIndex to theIndex & "<a href=\"" & this_link & "\">" & (name of theRecord) & "</>" & "<br>" & return
end if
else
set theIndex to theIndex & "<a href=\"" & this_link & "\">" & (name of theRecord) & "</>" & "<br>" & return
end if
end repeat
set theIndex to theIndex & "</body>" & return & "</html>"
set theRecord to item 1 of theSelection
if exists parent 1 of theRecord then
set theIndexName to short_base_name & " Index of: " & (name of parent 1 of theRecord as string)
create record with {name:theIndexName, type:html, source:theIndex} in parent 1 of theRecord
else
set theIndexName to short_base_name & " Index"
create record with {name:"Index", type:html, source:theIndex}
end if
on error error_message number error_number
if the error_number is not -128 then
try
display alert "DEVONthink Pro" message error_message as warning
on error number error_number
if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
end try
end if
end try
end tell
[size=85]Update: fixed a logic bomb in the code first posted. Sorry![/size]