Reformat script text for HTML (using Tex-Edit)
Reformat script text for HTML (using Tex-Edit)
- Subject: Reformat script text for HTML (using Tex-Edit)
- From: Gnarlodious <email@hidden>
- Date: Thu, 16 Sep 2004 00:19:06 -0600
Title: Reformat script text for HTML (using Tex-Edit)
Here’s my script to reformat text so as not to make Martin go blind. Runtime is about 2 minutes (450 processor) for this size script. If anyone knows how to script RTF let me know and it could be done without Tex-Edit.
Comments about readability are welcome.
-- http://Gnarlodious.com/Apple/AppleScript/
-- Recolor Applescript colors for HTML
-- Requires Tex-Edit http://Tex-Edit.com/
set pListPath to "~/Library/Preferences/com.apple.applescript.plist"
global nl
set nl to ASCII character 10
-- populate the variables with the default Applescript values
set osaOther to {"Courier", "p", 12, {32896, 0, 32896}}
set osaOperator to {"Verdana", "p", 12, {0, 0, 0}}
set osaLanguage to {"Verdana", "b", 12, {0, 0, 65535}}
set osaApplication to {"Verdana", "p", 12, {0, 0, 65535}}
set osaComments to {"Verdana", "i", 12, {19532, 19789, 19789}}
set osaValues to {"Verdana", "p", 12, {0, 0, 0}}
set osaIdentifier to {"Verdana", "p", 12, {16448, 32896, 0}}
set osaReference to {"Verdana", "p", 12, {32896, 0, 32896}}
set osaStyles to {a reference to osaOther, a reference to osaOperator, a reference to osaLanguage, a reference to osaApplication, a reference to osaComments, a reference to osaValues, a reference to osaIdentifier, a reference to osaReference}
set applescriptPrefs to do shell script "awk '/AppleScriptTextStyles/,/<\\/array>/' " & pListPath & "| sed -n '3,10p' | sed" & ¬
" -e 's| <string>|{\"|' " & ¬
" -e 's|;|\",\"|' " & ¬
" -e 's|;|\",|' " & ¬
" -e 's|;|,{|' " & ¬
" -e 's| |,|g' " & ¬
" -e 's|<\\/string>|}}|' "
repeat with i from 1 to count items of osaStyles
set item i of osaStyles to run script (paragraph i of applescriptPrefs)
end repeat
set newOther to {"Courier", "b", 12, {13107, 13107, 0}}
set newOperator to {"Verdana", "b", 12, {37954, 37954, 37954}}
set newLanguage to {"Verdana", "b", 12, {13107, 0, 13107}}
set newApplication to {"Verdana", "b", 12, {13107, 0, 0}}
set newComments to {"Verdana", "bi", 12, {0, 0, 0}}
set newValues to {"Verdana", "b", 12, {26214, 26214, 26214}}
set newIdentifier to {"Verdana", "bu", 12, {0, 13107, 13107}}
set newReference to {"Verdana", "b", 12, {0, 0, 13107}}
set targetStyles to {a reference to newOther, a reference to newOperator, a reference to newLanguage, a reference to newApplication, a reference to newComments, a reference to newValues, a reference to newIdentifier, a reference to newReference}
repeat with i from 1 to count items of targetStyles
set item i of targetStyles to (every item of item i of targetStyles)
end repeat
tell application "Script Debugger"
activate
set cursorPos to position of the selection
select the text of the front window
set theText to the selection
select insertion point cursorPos of the front window
end tell
-------------------------------------------------------------------------
on translatePref(textString)
do shell script "p=plain b=bold i=italic u=underline s=shadow o=outline c=condensed e=expanded" & nl & ¬
"out=`echo " & textString & " | sed -e 's|.|$&, |g' -e 's|, $||'`" & nl & ¬
"eval echo {$out}"
return (run script the result)
end translatePref
tell application "Tex-Edit Plus"
activate
make new window
tell front window
set the background color to white
set the contents to theText
repeat with n from 1 to count of style runs
repeat with row from 1 to 8
tell style run n
if color = item 4 of item row of osaStyles then
if size = item 3 of item row of osaStyles then
if font = item 1 of item row of osaStyles then
style
on styles of the result
if the result = my translatePref(item 2 of item row of osaStyles) then
set the color to item 4 of item row of targetStyles
set the size to item 3 of item row of targetStyles
set the font to item 1 of item row of targetStyles
set the style to my translatePref(item 2 of item row of targetStyles)
end if
end if
end if
end if
end tell
end repeat
end repeat
end tell
end tell
beep
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden