What is the best way to html-ize a script. I mean with the nice syntax highlighting etc.
Getting the rtf “script” of an .app and process that with textutil gives a nice result but that’s a lot of fiddling with files. But that won’t work with .scpt files (no easy access to the rtf representation).
use AppleScript version "2.5"
use framework "Foundation"
use framework "AppKit"
use scripting additions
set theFile to (choose file with prompt "Choose a script")
set {theScript, theError} to current application's NSAppleScript's alloc()'s initWithContentsOfURL:theFile |error|:(reference)
if theScript is missing value then error theError's localizedDescription() as text
set theAttString to theScript's richTextSource()
set elementsToSkip to {"doctype", "html", "body", "xml", "style", "p", "font", "head", "span"} -- ammend to taste
set theDict to current application's NSDictionary's dictionaryWithObjects:{current application's NSHTMLTextDocumentType, elementsToSkip} forKeys:{current application's NSDocumentTypeDocumentAttribute, current application's NSExcludedElementsDocumentAttribute}
set {htmlData, theError} to theAttString's dataFromRange:{0, theAttString's |length|()} documentAttributes:theDict |error|:(reference)
if htmlData = missing value then error theError's localizedDescription() as text
set theString to current application's NSString's alloc()'s initWithData:htmlData encoding:(current application's NSUTF8StringEncoding)
And since there are no CSS classes associated to the tags, it is not possible to associate an external CSS sheet to the result and get the syntax coloring
But it’s not that different. There are more tags with your method than with the other, but since it’s not possible to access an rtf file for scripts that’s the only solution ! Thank you again