The script usually takes 5 to 7 sec to run. However, sometimes (not very often) it will take 20 or more secs and I can’t figure out why.
if appActive("Mail") then
findFlagged()
end if
on findFlagged()
-- careful ANSI esc may not show in some editors
set flaggedIcons to {{0, "[31;1m • [32;0m "}, {1, "[31;1m [32;0m "}, {2, "[33;1m • [32;0m "}, {3, "[32;1m • [32;0m "}, ¬
{4, "[34;1m • [32;0m "}, {5, "[35;1m • [32;0m "}, {6, "[30;1m • [32;0m "}}
set newline to ASCII character 10
set finalText to "Flagged Mail:" & newline
tell application "Mail"
set target_account to name of every account
repeat with a from 1 to count of target_account
set theAccount to item a of target_account
set theMessages to (every message in mailbox "INBOX" of the account theAccount whose flagged status is true)
repeat with i from 1 to number of items in theMessages
set thisMessage to item i of theMessages
set theFlag to (flag index of thisMessage)
set fromMsg to (sender of thisMessage as string)
set subjMsg to (subject of thisMessage as string)
set theID to (message id of thisMessage)
repeat with x from 1 to number of items in flaggedIcons
if theFlag = item 1 of item x of flaggedIcons then
set theIcon to item 2 of item x of flaggedIcons
end if
end repeat
set finalText to finalText & theIcon & word 1 of fromMsg & ": " & subjMsg & newline
end repeat
end repeat
end tell
-- set fPath to "Macintosh HD:Users:username:Library:Logs:"
set fPath to "Macintosh HD:Users:username:Desktop:" --file testing
set theFile to POSIX path of fPath & "flagged1.log"
open for access theFile with write permission
set eof theFile to 0
write finalText to theFile as text
close access theFile
end findFlagged
on appActive(appName)
tell application "System Events" to (name of processes) contains appName
end appActive
James Roberts
"Nothing travels faster than the speed of light, with the possible exception of
bad news, which obeys its own set of laws" ~ Douglas Adams