Index DEVONthink help
This script indexes DEVONthink’s help.
It first duplicates the internal help to a new Finder folder, then indexes the duplicated help.
If you don’t like the indexed help anymore you can delete it without any risk.
How to index:
-
Run the script from Script Editor.app.
-
After 30 seconds you’ll find a new group in your global inbox.
-
You can move this group or rename it and/or the records in DEVONthink (not in Finder).
-
After a DEVONthink update delete the dated indexed help and run the script again.
How to delete:
-
Select the indexed group
-
Select menu
Data > Show in Finder
(but do nothing) -
Switch back to DEVONthink
-
Move the indexed group to trash
-
Empty the trash
-
Switch back to Finder
-
Move the folder to trash (and confirm the dialog)
That’s it.
Thanks Jim, you’ve built a great resource!
-- Index DEVONthink help
-- This script first duplicates DEVONthink's internal help to a new Finder folder. You can delete the indexed group (e.g. after an update) without any risk.
-- Run the script from Script Editor.app. After 30 seconds you'll find a new group in your global inbox.
-- You can move this group or rename it and/or the records in DEVONthink (not in the Finder folder).
-- How to delete: https://discourse.devontechnologies.com/t/indexing-help-or-macos-help-viewer-vs-devonthink/46475/20
set theSuperFolder_Path to POSIX path of (path to application support from user domain) & "DEVONthink 3/DEVONthink Help (indexed)/"
set theResources_Path_HFS to ((path to of application id "DNtp") & "Contents:Resources:DEVONthink.help:Contents:Resources:") as string
set createSuperFolder to do shell script "mkdir -p " & quoted form of theSuperFolder_Path
tell application "Finder"
try
try
set theSuperFolder to folder (POSIX file theSuperFolder_Path as alias)
on error
error theSuperFolder_Path
end try
try
set theResourcesFolder to folder theResources_Path_HFS as alias
on error
error theResources_Path_HFS
end try
on error error_message number error_number
activate
if the error_number is not -128 then display alert "Finder" message "Can't get folder: \"" & error_message & "\"" as warning
return
end try
end tell
tell application id "DNtp"
try
set theHelpFolder_Name to "DEVONthink Help - " & version as string
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
tell application "Finder"
try
try
set theHelpFolder to make new folder at theSuperFolder with properties {name:theHelpFolder_Name}
on error error_message number error_number
if the error_number is -48 then
error "Can't make folder. Folder already exists: \"" & theSuperFolder_Path & theHelpFolder_Name & "\""
else
error error_message number error_number
end if
end try
duplicate folder theResources_Path_HFS to theHelpFolder
set locked of entire contents of theHelpFolder to true
set locked of theHelpFolder to true
on error error_message number error_number
activate
if the error_number is not -128 then display alert "Finder" message error_message as warning
return
end try
end tell
tell application id "DNtp"
try
set theDatabase to inbox
set theHelpGroup to indicate (theHelpFolder as alias) to root of theDatabase
set thePath to path of theHelpGroup
set locking of (contents of theDatabase whose path starts with thePath) to true
set exclude from search of (contents of theDatabase whose path starts with thePath and type is not html) to true
set exclude from see also of (contents of theDatabase whose path starts with thePath and type is not html) to true
my excludeFrom(theHelpGroup)
set theHTMLRecords to (contents of theDatabase whose path starts with thePath and type is html)
repeat with thisHTMLRecord in theHTMLRecords
set theSource to source of thisHTMLRecord as string
try
set thisTitle to (item 1 of (my tid(item 2 of (my tid(theSource, "<title>")), "</title>"))) as string
if thisTitle ≠ "" then
if thisTitle = "DEVONthink Documentation" then set thisTitle to "DEVONthink Documentation : " & (item 1 of (my tid(item 3 of (my tid(theSource, "<span class=\"topic\">")), "</span>"))) as string
if thisTitle contains "&" then set thisTitle to my replace_String(thisTitle, "&", "&")
if thisTitle ≠ "" then set name of thisHTMLRecord to theHelpFolder_Name & " - " & thisTitle
end if
end try
end repeat
try
set theSmartGroup to create record with {type:smart group, search predicates:"kind:html", search group:theHelpGroup, name:theHelpFolder_Name} in theHelpGroup
set theWindow to open window for record theHelpGroup
set selection of theWindow to {get record at ((location of theHelpGroup as string) & (name of theHelpGroup as string) & "/Resources/" & theHelpFolder_Name & " - DEVONthink Help")}
activate
end try
on error error_message number error_number
activate
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
on excludeFrom(theGroup)
tell application id "DNtp"
try
set locking of theGroup to true
set exclude from classification of theGroup to true
set theChildGroups to children of theGroup whose type is group
repeat with thisChildGroup in theChildGroups
my excludeFrom(thisChildGroup)
end repeat
on error error_message number error_number
error number -128
end try
end tell
end excludeFrom
on tid(theText, theDelimiter)
set d to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
set TextItems to text items of theText
set AppleScript's text item delimiters to d
return TextItems
end tid
on replace_String(theText, oldString, newString)
local ASTID, theText, oldString, newString, lst
set ASTID to AppleScript's text item delimiters
try
considering case
set AppleScript's text item delimiters to oldString
set lst to every text item of theText
set AppleScript's text item delimiters to newString
set theText to lst as string
end considering
set AppleScript's text item delimiters to ASTID
return theText
on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't replaceString: " & eMsg number eNum
end try
end replace_String