ScriptToEmail (now with added speed)
ScriptToEmail (now with added speed)
- Subject: ScriptToEmail (now with added speed)
- From: has <email@hidden>
- Date: Sat, 29 Sep 2001 12:54:57 +0100
Still to make a decision on using key combos or character names for the
conversion list (could use more feedback - hint-hint:), but meantime I've
got it running much faster (8x?) by reworking the convertcharacters()
handler. Enjoy...
has
===================================
property conversionlist : {"[ASCII-128]", "[ASCII-129]", "[ASCII-130]",
"[ASCII-131]", "[ASCII-132]", "[ASCII-133]", "[ASCII-134]", "[ASCII-135]",
"[ASCII-136]", "[ASCII-137]", "[ASCII-138]", "[ASCII-139]", "[ASCII-140]",
"[ASCII-141]", "[ASCII-142]", "[ASCII-143]", "[ASCII-144]", "[ASCII-145]",
"[ASCII-146]", "[ASCII-147]", "[ASCII-148]", "[ASCII-149]", "[ASCII-150]",
"[ASCII-151]", "[ASCII-152]", "[ASCII-153]", "[ASCII-154]", "[ASCII-155]",
"[ASCII-156]", "[ASCII-157]", "[ASCII-158]", "[ASCII-159]", "[OPT-t]",
"[OPT-SHIFT-8]", "[OPT-4]", "[ASCII-163]", "[OPT-6]", "[OPT-8]", "[OPT-7]",
"[OPT-s]", "[OPT-r]", "[OPT-g]", "[OPT-2]", "[ASCII-171]", "[ASCII-172]",
"[OPT-=]", "[OPT-SHIFT-']", "[OPT-SHIFT-o]", "[OPT-5]", "[OPT-SHIFT-=]",
"[OPT-,]", "[OPT-.]", "[OPT-y]", "[OPT-m]", "[OPT-d]", "[OPT-w]",
"[OPT-SHIFT-p]", "[OPT-p]", "[OPT-b]", "[OPT-9]", "[OPT-0]", "[OPT-z]",
"[OPT-']", "[OPT-o]", "[OPT-SHIFT-/]", "[OPT-1]", "[OPT-l]", "[OPT-v]",
"[OPT-f]", "[OPT-x]", "[OPT-j]", "[OPT-\\]", "[OPT-SHIFT-\\]", "[OPT-;]",
"[OPT-SPACE]", "[ASCII-203]", "[ASCII-204]", "[ASCII-205]",
"[OPT-SHIFT-q]", "[OPT-q]", "[OPT--]", "[OPT-SHIFT--]", "[OPT-[]",
"[OPT-SHIFT-[]", "[OPT-]]", "[OPT-SHIFT-]]", "[OPT-/]", "[OPT-SHIFT-v]",
"[ASCII-216]", "[ASCII-217]", "[OPT-SHIFT-1]", "[ASCII-219]",
"[OPT-SHIFT-3]", "[OPT-SHIFT-4]", "[OPT-SHIFT-5]", "[OPT-SHIFT-6]",
"[OPT-SHIFT-7]", "[OPT-SHIFT-9]", "[OPT-SHIFT-0]", "[OPT-SHIFT-w]",
"[OPT-SHIFT-e]", "[ASCII-229]", "[ASCII-230]", "[ASCII-231]",
"[ASCII-232]", "[ASCII-233]", "[ASCII-234]", "[ASCII-235]", "[ASCII-236]",
"[ASCII-237]", "[ASCII-238]", "[ASCII-239]", "[OPT-SHIFT-k]",
"[ASCII-241]", "[ASCII-242]", "[ASCII-243]", "[ASCII-244]",
"[OPT-SHIFT-b]", "[ASCII-246]", "[ASCII-247]", "[ASCII-248]",
"[ASCII-249]", "[ASCII-250]", "[ASCII-251]", "[ASCII-252]", "[ASCII-253]",
"[ASCII-254]", "[ASCII-255]"}
property indentspaces : "
"
property formatstring :
"======================================================================"
property infostring : "[formatted using ScriptToEmail -
http://www.????? -
soothing relief for list pains]"
set oldTIDs to text item delimiters of AppleScript
set texttoconvert to the clipboard as string
if texttoconvert is {} then
display dialog "Clipboard doesn't contain text." buttons {"Oops"}
default button 1
else
display dialog "Format the clipboard as email-friendly AppleScript?
(This may take a few seconds.)"
set text item delimiters of AppleScript to {return}
set texttoconvert to every text item of texttoconvert
set text item delimiters of AppleScript to {""}
set texttoconvert to convertcharacters(texttoconvert)
set texttoconvert to replaceindents(texttoconvert)
set text item delimiters of AppleScript to {return}
set the clipboard to formatstring & return & return &
wraplines(texttoconvert) & return & return & formatstring & return &
infostring & return
set text item delimiters of AppleScript to oldTIDs
end if
-----------------------
on convertcharacters(texttoconvert)
repeat with linecount from 1 to count of texttoconvert
set newtext to every item of (item linecount of texttoconvert)
repeat with x from 1 to count of newtext
if (ASCII number (item x of newtext)) > 127 then set (item x of
newtext) to item ((ASCII number (item x of newtext)) - 127) of
conversionlist
end repeat
set (item linecount of texttoconvert) to (newtext as string)
end repeat
return texttoconvert
end convertcharacters
on replaceindents(texttoconvert)
repeat with linecount from 1 to count of texttoconvert
set eachline to item linecount of texttoconvert
ignoring white space
if eachline = "" then set eachline to ""
end ignoring
if eachline begins with tab then
repeat with x from 1 to count of eachline
if item x of eachline is not tab then exit repeat
end repeat
set eachline to (text 1 thru ((x - 1) * 3) of indentspaces) &
(text x thru -1 of eachline)
end if
set item linecount of texttoconvert to eachline
end repeat
return texttoconvert
end replaceindents
on wraplines(texttoconvert)
repeat with linecount from 1 to count of texttoconvert
set eachline to item linecount of texttoconvert
if (count of eachline) > 70 then
ignoring white space
repeat with x from 70 to 40 by -1
if item x of eachline = "" then exit repeat
end repeat
end ignoring
if x = 40 then set x to 70
set firstline to text 1 thru x of eachline
set restoftext to "[NO-BREAK]" & (text (x + 1) thru -1 of eachline)
set item linecount of texttoconvert to {firstline,
wraplines({restoftext})}
end if
end repeat
return texttoconvert
end wraplines