Shell worksheets are stored in a private document format which is not text-based. This format allows BBEdit to store auxiliary data in the worksheet file’s data fork, thus ensuring that worksheets can safely be stored in version control systems that are not resource fork aware.
I’ve no idea Perhaps it would be possible to have a custom whitelist of extensions which don’t pop up the protocol. Would be nice to index a folder of worksheets to have them in DEVONthink search results.
Since the content is not text-based, that’s not going to happen.
In BBEdit you can export a .worksheet as .txt – so if you wrote a new routine in BBEdit to export all .worksheets as text in the same folder(s) where the .worksheets are stored, then you would end up with a .txt sidecar file next to your .worksheet files, and DEVONthink would be able to index and search those.
Funny, I did something similar this week as I started using git and wrote a textconv filter to get nice plain text diffs of Nisus Writer zrtf files. I’ll try your suggestion
BBEdit has a wonderful scripting dictionary, and “export” is one of the commands – should be able to do a simple conversion script that Hazel operates.
Ok tried a script for Hazel but Finder does really strange things with the comments …
All files have comments (I can see them in the info windows) but most don’t show in a Finder window - and some only show a part?!
Makes no difference if Hazel set the comments or if the smart rule did it with an indexed folder. Restarting Finder didn’t help.
-- External Hazel script: Set BBEdit Worksheet content as comment
on hazelProcessFile(theFile)
tell application "Finder"
try
set thisFile to file theFile
if (name extension of thisFile) = "worksheet" then
set thePath to POSIX path of (thisFile as text)
set theWorksheetContents to do shell script "/usr/libexec/PlistBuddy -c 'Print WorksheetContents' " & quoted form of thePath
if theWorksheetContents = "" then
set theWorksheetContents to "[content too long]" -- seems PlistBuddy has a limit
else if (count of characters in theWorksheetContents) > 256 then
set theWorksheetContents to (characters 1 thru 256 in theWorksheetContents) as string
end if
set cleanWorksheetContents to my replace_String(theWorksheetContents, return, space)
set comment of thisFile to cleanWorksheetContents
return true
else
return false
end if
on error error_message number error_number
if the error_number is not -128 then display alert "Hazel" message error_message as warning
return
end try
end tell
end hazelProcessFile
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
This smart rule works and Finder now shows comments correctly
-- Set visible BBEdit Worksheet content as comment
on performSmartRule(theRecords)
tell application id "DNtp"
try
repeat with theRecord in theRecords
set thePath to path of theRecord
set theWorksheetContents to do shell script "/usr/libexec/PlistBuddy -c 'Print WorksheetContents' " & quoted form of thePath
if theWorksheetContents = "" then set theWorksheetContents to "[content too long]" -- PlistBuddy seems to have a limit what it can extract
set cleanWorksheetContents to my replace_String(theWorksheetContents, return, space) -- Finder doesn't like returns in comments
set comment of theRecord to cleanWorksheetContents
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
end performSmartRule
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