In the 10 possible types of reports I have in my Mail Manager app, one is for a years daily tally counts of incoming email, and extra jobs included in the emails.
The total of the content characters can reach over 50,000, and I’m trying to set the color of one character, and the size of another.
At the moment, I’ve been counting and setting them individually, but have tried setting them as blocks or strings of like characters, which reduces the time quite a bit.
But it’s still a PITA to wait for.
I’ve included code below which reflects an average years data, without details included, and the two methods take 243 and 145 seconds respectively, which I’d like to improve if possible; (my quest for the need for speed is undiminished). Each character represents 5 emails, or 5 extra jobs.
Any one know of a way to speed this up? For instance, is it possible to format the data before adding it to Mail as content?
set textcolor to {18 * 256, 15 * 256, 243 * 256}
set the_content to ""
set c to current date
copy c to cc
set year of cc to (year of cc) - 1
repeat with x from 1 to 355
set the_content to the_content & (year of cc & " " & month of cc as text) & " " & day of cc & tab & "●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆" & return as text
set cc to cc + days
end repeat
say (count of the_content)
set c to current date
tell application "Mail"
activate
set p to 4
set newMessage to make new outgoing message with properties {visible:true, subject:"test 1", content:the_content}
set p to 5
tell content of newMessage
try
set y to count of the_content
set color of characters 1 thru y to textcolor
end try
try
repeat with x from 1 to (count of the_content)
if character x of the_content = "●" then
set color of character x to {56342, 2442, 607}
end if
if character x of the_content = "◆" then
set size of character x to 10
end if
end repeat
end try
set p to 6
end tell # content
end tell # application "Mail"
set n to ((current date) - c) as text
set c to current date
tell application "Mail"
activate
set p to 4
set newMessage to make new outgoing message with properties {visible:true, subject:"test 2", content:the_content}
set p to 5
tell content of newMessage
try
set y to count of the_content
set color of characters 1 thru y to textcolor
end try
try
set x to 0
set xxx to (count of the_content)
repeat
set x to x + 1
if character x of the_content = "●" then
set xx to 0
repeat
set xx to xx + 1
if character (x + xx) of the_content ≠ "●" then
set color of characters x through (x + (xx - 1)) to {56342, 2442, 607}
set x to x + xx
exit repeat
end if
end repeat
end if
if character x of the_content = "◆" then
set xx to 0
repeat
set xx to xx + 1
if character (x + xx) of the_content ≠ "◆" then
set size of characters x through (x + (xx - 1)) to 10
set x to x + xx
exit repeat
end if
end repeat
end if
if x ≥ xxx then exit repeat
end repeat
end try
set p to 6
end tell # content
end tell # application "Mail"
tell application "System Events" to display dialog n & return & ((current date) - c)