• 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: How to select a message in Mail
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to select a message in Mail


  • Subject: Re: How to select a message in Mail
  • From: kai <email@hidden>
  • Date: Tue, 23 Jan 2007 01:19:26 +0000


On 20 Jan 2007, at 12:42, fishy wrote:

I'm writing a script to be used by Mail rules to automatically set
text encoding of some mails (that they didn't encoded well so Mail
can't get their encoding automatically).

I've found 2 examples that one can get messages returned by rules, and
one can "click" on the menus (so that can change encoding of a
selected mail), but don't know how to combine them together.

[snip: scripts - retained below for reference]

So what I need to do is, in the "do something here" in the Script 1,
select the mail, and insert Script 2.

So, anyone have some advice on how to select the message? I've tried
"select eachMessage" and "select message eachMessage" but seems
neither works.

It's unclear how the messages to process are to be defined, fishy - whether they'll be filtered incoming messages, or simply a selection of received messages.


While this shouldn't normally make a difference, I've experienced buggy behaviour when attempting to run certain scripts, such as the one below, from a Mail rule. This may, of course, be a local issue (although Mail's track record causes me to doubt this).

If the aim is to change the text encoding of the currently selected messages, then my own preference would be to run the script from Script Menu, rather than from a Mail rule. However, since your mileage may vary, you might like to try both. The routine is configured to run from either - as well as from a script editor or as an application.

---------------

property target_encoding : "Chinese (GB 18030)"

to set_encoding()
	activate application "Mail"
	tell application "System Events" to ¬
		tell menu item target_encoding of menu 1 of ¬
			menu item "Text Encoding" of menu 1 of ¬
			menu bar item "Message" of menu bar 1 of ¬
			application process "Mail" to if (exists) then click
end set_encoding

using terms from application "Mail"
to perform mail action with messages theMessages
tell application "Mail"
if (count message viewers) is 0 then make message viewer
tell message viewer 1
set index to 1 -- make sure it's frontmost
set preview pane is visible to true -- to enable menu items
set mBoxes to (get selected mailboxes)
repeat with theMessage in theMessages
set mBox to {theMessage's mailbox}
if mBox is not in mBoxes then
set mBoxes to mBoxes & mBox
repeat until mBox is in (get selected mailboxes)
set selected mailboxes to mBoxes
delay 0.2
end repeat
end if
repeat while (count visible messages) is 0 -- in case the mailbox was changed
delay 0.1
end repeat
repeat until (count selected messages) is 0 -- clear any current selection
set selected messages to {}
delay 0.1
end repeat
repeat until (count selected messages) is 1 -- now select the target message
set selected messages to {theMessage}
delay 0.2
end repeat
my set_encoding()
end repeat
end tell
end tell
end perform mail action with messages
end using terms from


(* run handler to test/execute handler from Script Editor, etc. *)

tell application "Mail"
	activate
	set msgs to selection
	tell me to perform mail action with messages msgs
end tell

---------------



original scripts:

The first script is:

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			repeat with eachMessage in theMessages
				(* do something here *)
			end repeat
		end tell
	end perform mail action with messages
end using terms from

this script can get the messages returned by the rule (to "eachMessage")

And the secont script is:

tell application "System Events"
	if UI elements enabled then
		click menu item "Chinese (GB 18030)" of menu "Text Encoding" of menu
item "Text Encoding" of menu "Message" of menu bar 1 of process "Mail"
	end if
end tell

this script can change the text encoding of the selected mail to GB18030.

--- kai


_______________________________________________ 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/mailman//archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: How to select a message in Mail
      • From: fishy <email@hidden>
References: 
 >How to select a message in Mail (From: fishy <email@hidden>)

  • Prev by Date: Re: Newbe question on Handler
  • Next by Date: Re: XML parsing from AppleScript
  • Previous by thread: How to select a message in Mail
  • Next by thread: Re: How to select a message in Mail
  • Index(es):
    • Date
    • Thread