• 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
Re: Scripting Mail
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting Mail


  • Subject: Re: Scripting Mail
  • From: "koenig.yvan" <email@hidden>
  • Date: Sun, 13 Jan 2013 22:24:29 +0100


Le 13/01/2013 à 21:40, James Roberts <email@hidden> a écrit :

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.
…


try to use :

on run
run script main
end run

script main
if appActive("Mail") then
findFlagged()
end if
end script

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 "}}
# ASCII character is deprecated
# this character is defined by AppleScript as linefeed
# set newline to ASCII character 10
set finalText to "Flagged Mail:" & linefeed # newline
tell application "Mail"
set target_account to name of every account
repeat with theAccount in target_account
set theMessages to (every message in mailbox "INBOX" of the account theAccount whose flagged status is true)
repeat with thisMessage in theMessages
set theFlag to (flag index of thisMessage)
# these two properties are already strings, no need to coerce them again
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 & linefeed # 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


Yvan KOENIG (VALLAURIS, France) dimanche 13 janvier 2013 22:24:22


 _______________________________________________
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: James Roberts <email@hidden>
References: 
 >Scripting Mail (From: James Roberts <email@hidden>)

  • Prev by Date: Scripting Mail
  • Next by Date: auto mount not working
  • Previous by thread: Scripting Mail
  • Next by thread: Re: Scripting Mail
  • Index(es):
    • Date
    • Thread