• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Scripting Mail
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Scripting Mail


  • Subject: Scripting Mail
  • From: James Roberts <email@hidden>
  • Date: Sun, 13 Jan 2013 15:40:19 -0500

I have been using this script for a couple of years now with not problems. I used GeekTool to run it once every minute and then had GeekTool display the resultant file. Lately (sense ML) it started dragging the Mail GUI down to the point were it was unusable while the script was running. For “fun” I saved the script as an app and had launchd run it, with the same results. Any suggestions on changes to the script or launch methods would be great.
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
email@hidden

"Nothing travels faster than the speed of light, with the possible exception of
bad news, which obeys its own set of laws" ~ Douglas Adams




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Scripting Mail
      • From: "koenig.yvan" <email@hidden>
  • Prev by Date: Re: Setting Calendar Category in Apple Script
  • Next by Date: Re: Scripting Mail
  • Previous by thread: Re: Setting Calendar Category in Apple Script
  • Next by thread: Re: Scripting Mail
  • Index(es):
    • Date
    • Thread