Scripting Mail: Command to select a message?

Is there an easy way in AppleScript to select a given message?
My problem is that the "Remove Attachments" command that I use all the time deselects the message after removing the attachment. I want to use a script that stores the current selection in a global variable, then apply the "Remove Attachments" command, and then use another script to reselect the previously selected message using the global variable.
I would then create a macro in Keyboard Maestro to do all three steps, since Mail's AppleScript dic does not include a command for removing attachments.
Any help would be appreciated.
Message was edited by: Pierre Igot
Message was edited by: Pierre Igot

Pierre Igot wrote:
Also, if you look at my sample script higher up, you'll see that there are problems with the selection even when you don't use the Remove Attachments command, i.e. even when message IDs don't change.
Even if you do something as simple as:
1) get the current selection
2) press the Up cursor key to select the message above
3) try to reselect what was selected in 1)
it doesn't work reliably. I don't think pressing the Up key changes any message IDs, and yet there is still a problem with reselecting what was selected.
Pierre
LATEXT - Literature, Music & Visuals @ www.latext.com
BETALOGUE - Weblog at www.betalogue.com
OK, so it would be a bug in the Mail of Snow Leopard.
Here, it works well.
Try a another script, but it will be slower :
property t_ids : {}
tell application "Mail"
activate
tell message viewer 1 to set {t_ids, sel} to {id of messages, selected messages}
set a_id to id of item 1 of sel
tell application "System Events" to tell process "Mail"
click menu item "Remove Attachments" of menu 1 of menu bar item "Message" of menu bar 1
end tell
delay 2
tell message viewer 1
set t_ids2 to id of messages
if t_ids2 is not t_ids then set a_id to my searchNewID(t_ids2)
set selected messages to {}
if a_id is not "" then repeat
tell application "System Events" to tell process "Mail" to keystroke character id 31
delay 0.2
try
set b to id of item 1 of (get selected messages)
if b = a_id then exit repeat
end try
end repeat
end tell
end tell
set t_ids to {}
on searchNewID(L)
repeat with i in L
if contents of i is not in t_ids then return contents of i
end repeat
return ""
end searchNewID

Similar Messages

  • Mail can't Select All messages in this Conversation

    For years I have used Cmd-Shift-K in Mail to select all messages in the same conversation. This particularly useful, for example, when reading replies to posts in Apple discussions. When I select a message, all the messages with the same topic appear in light blue and Cmd-Shift-K (or View->Select->All Messages in this Conversation) allowed me to select them all.
    Since upgrading to Yosemite, the visual cues on the messages are still there (I have the box to "Highlight messages with color when not grouped") but the command to select them is greyed out, and Cmd-Shift-K just beeps in error.
    Are other people seeing this?

    Send Apple feedback. They won't answer, but at least will know there is a problem. If enough people send feedback, it may get the problem solved sooner.
    Mail Feedback

  • Mail: do NOT select next message on delete/move

    Hi.
    When using mail and I move a message to another folder or delete a message, the next message is automatically selected and displayed on the preview pane. I want to be able to delete and move a message without the following being selected, in other words, I do not want mail to automatically select the next message.
    How can I do that? I did not find an option to "not select by default".
    Help is appreciated.

    I don't think this behavior is unique to the move message command.
    I notice that if I select a message, quit Apple Mail and relaunch it it will still try and remember the last selected email, although it will pull focus off the message the preview pane still shows it.
    I don't know if there is anything you can to to not let Apple Mail refocus.  Maybe another Mail App? 
    - Stephen
    http://learni.st/users/Riptide360/boards/69477-optimizing-apple-mail

  • Attempt to drag a message and Mail instead selects multiple messages

    I used to be able to quickly grab a message and drag it to a folder. Now I have to click and hold before the message is grabbed. If I try to do it quickly, Mail instead begins selecting the message I am trying to drag and continues autoscrolling and selecting all the messages below it.
    I drag messages to folders far more often than I select multiple messages, so this is not a boost to my productivity. It breaks a pretty basic user interface convention too. I hope this change doesn't make its way into the Finder!
    For the record: Overall I am VERY happy with Snow Leopard.

    Hi Ernie,
    Thanks for the reply. You're right (as was the original "helpful"-marked post) - dragging directly sideways does work to avoid changing the selection. However, I have a full vertical screen of message folders and my messages being dragged are almost always at the bottom (I don't use a preview pane), and I know for sure that I never had to drag sideways before dragging up before Snow Leopard.
    The problem is even worse on Apple's 30" monitor, as you might imagine.
    I simply need to be able to disable this undesired "multi-select mail items in the list with the mouse" functionality that (to my years of use) was never there in the past. I'm betting there is some preference setting I could put in, if only I knew what it was.
    Thanks,
    Doug

  • Mail Services Newbie - Selective Relaying?

    Hello everyone. I'm fairly new to OS X Mail Services, so please forgive my naiveté when asking this question. I'm a CS professor at a small college, and we recently purchased and installed an Xserve for use by our department's students. Everything is working fine with the exception of mail services. The problem is that, for local emails (@ourschool.edu), I need to relay through our (separate) SMTP server. This works fine when sending mail to a local address. However, when sending email to an outside address (another other than @ourschool.edu), I do not need to relay the messages through our SMTP server.
    Is there a way to configure Mail services to "selectively" relay messages based on their destination domain? Basically, if the destination is @ourschool.edu, I want to relay it. Otherwise, just send it to the destination directly.
    I know that one solution would be to open up our SMTP server for total/complete relaying from our Xserve, but I was wondering if I could accomplish the same thing without the need for relaying everything.
    Thanks!

    You cannot do this via the GUI, but if you do not mind using Terminal, this can be achieved by using transport maps.
    There are several ways of doing this, but roughly it goes like this:
    Make a copy of /etc/postfix/main.cf first.
    Edit /etc/postfix/main.cf
    comment out your relayhost setting if you have already set it:
    #relayhost = mysmtpserver.mydomain.com
    add:
    transport_maps = hash:/etc/postfix/transport_maps
    create a file:
    /etc/postfix/transport_maps
    with these contents:
    ourschool.edu smtp: mysmtpserver.mydomain.com
    otherdomain.edu smtp: othersmtpserver.mydomain.com
    save it and issue:
    sudo postmap /etc/postfix/transport_maps
    sudo postfix reload
    For more info, look at the transport maps examples here: http://www.postfix.org/STANDARDCONFIGURATIONREADME.html
    HTH,
    Alex
    P.S. The forum software mangles above sample a bit, so make sure you check the link. mysmtpserver.mydomain.com should be in square brackets and there is a * before the last colon

  • JavaScript for Automation Cannot Use Scripting Addition Commands

    Attempting to recreate the example script for Messages called "Speak Events" with the new JavaScript for Automation in Yosemite, I found that it is impossible to use any scripting addition commands. For example:
    Messages = Application.currentApplication()
    Messages.includeStandardAdditions = true
    function messageReceived(m, e) {
         Messages.say(m)
    I have removed all the other (annoyingly) necessary function overrides for brevity. Similar AppleScript code functions just fine, but this will result in a privilege error because the system wrongly categorizes it as being sent cross-application. Is there any estimate on a bug fix for this?
    I've tried everything I can think of to work around this issue, even adding /usr/bin/osascript to the Security & Privacy Accessibility listing ("Allow the apps below to control your computer") which is not possible without editing the SQLite DB.
    The documentation included in Script Editor is also woefully inadequate, lacking a readable listing of what exactly is being passed into the handler function. How can I translate an AppleScript line like "received theMessage from theBuddy for theChat with eventDescription" into a reasonable function signature for JavaScript?

    It is a big SDK and to learn its features requires a lot of reading. But to start with I guess I should start with "Introduction to SDK".
    Since you want to control Acrobat from another application you should consider this under "Interapplication communication". You will be using OLE/COM.

  • "Command-i" which was so useful in being able to selectively delete messages from the servers no longer works. Is their a replacement? Will it be fixed? Or should I change my mail application?

    "Command-i" which was so useful for selectively deleting messages from servers has disappeared in  Maverick. I wonder if it has been replaced by something else or should I look into other mail applications.

    Hmmm.  Which Mail program are you referring to?
    in Mac Mail command -i used to bring up the Account info pane on the server  (10.8.5)
    Now it seems you have to use the gear at the bottom in "Mail Activity" to get the drop down (10.9) :

  • Possible to select multiple messages in Mail?

    I'm in the process of switching to Mail and am setting up rules. I want to apply a rule to multiple messages at one time, instead of applying the rule to each individual message, one by one. I cannot find a way to Select All or otherwise apply a rule to a bunch of messages (that are already in my InBox) all at once. Can anyone help? Thank you!

    Camelot wrote:
    to select all messages in the current mailbox you enter command+A. then use "apply rules" from the Message menu. you can also do it with just a few selected messages. select them, control-click on the selected messages and choose "apply rules".
    Interesting interpretation of the OP's request.
    I read the request as wanting to take one action that applied to many messages, rather than apply one rule many times.
    For example, consider a rule that forwards the message to some other address. Selecting all messages and running the rule will generate multiple new messages - one per selected item.
    that was my understanding of what the OP wanted. perhaps I'm wrong. let's wait for the OP to respond and clarify what he/she really wants.
    Conversely, and how I interpreted the request, an AppleScript could collate all the selected messages and combine them into one new message - essentially running the 'forward' on many items at once.
    I'll be interesting to see the OP's response to see which matches his requirements.
    Message was edited by: V.K.

  • Unable to select multiple messages in Mail.

    Hi,
    I can't select multiple messages in Mail app. After selecting few, all of them automatically deselects. This is really annoying. I'm on 6.1.2 iP5, and this is happening from the begining. Never happened before on my iP4. The other problem with mail app is that it keeps opening my "first on the account list" e-mail account, and please don't tell me that this is normal since it never happened before. Sometimes when I try to open a random account I see a black screen
    see an image below.
    Please help me as this is driving me crazy.

    Camelot wrote:
    to select all messages in the current mailbox you enter command+A. then use "apply rules" from the Message menu. you can also do it with just a few selected messages. select them, control-click on the selected messages and choose "apply rules".
    Interesting interpretation of the OP's request.
    I read the request as wanting to take one action that applied to many messages, rather than apply one rule many times.
    For example, consider a rule that forwards the message to some other address. Selecting all messages and running the rule will generate multiple new messages - one per selected item.
    that was my understanding of what the OP wanted. perhaps I'm wrong. let's wait for the OP to respond and clarify what he/she really wants.
    Conversely, and how I interpreted the request, an AppleScript could collate all the selected messages and combine them into one new message - essentially running the 'forward' on many items at once.
    I'll be interesting to see the OP's response to see which matches his requirements.
    Message was edited by: V.K.

  • Apple script to select a message

    For my apple script I need to select the last message in the Inbox in Mail. How do I do that?

    If you mean the most recently received, you need the (non-intuitive) first message,eg:
    first message of mailbox "INBOX" of account ".Mac Account"

  • After aborted rebuild in Mail: I can see and select the message in the center pane and when I click on it to display, I get "Loading" text, but nothing comes up

    I have searched quite a bit to find a resolution to this problem, with no success. Any help would be appreciated.
    I decided to rebuild my inboxes by following this advice: http://support.apple.com/kb/PH11704. The rebuild took several hours and at 96% (4 minutes remaining apparently), the indexing froze (that is, after 8 hours, the message was still telling me "4 minutes left"). I forced quit mail, restored the previous Envelope files from the trash, and everything seemed fine.
    However, since this failed attempt, I can see and select the message in the center pane and when I click on it to display, I get "Loading" text, but nothing comes up. All messages in my various inboxes have the reloading problem, EXCEPT messages that I downloaded since the aborted rebuild (in other words, there are about 40 messages that I downloaded since I tried the rebuild and I have no problem with these). The other 70,000 messages however wont load, even though I can see them in the centre pane and spotlight has no problem finding them and showing me their contents (when I hover the mouse over the message). When I click on the message in spotlight, mail opens and the loading problem re-occurs.
    Since then, based on various suggestions I found for similar issues, I have used Disk Utility to verify and repair permissions and the drive. I used Onix to rebuild the Mail index (that only took about a minute - I am not sure how to interpret this when compared to the hours the rebuild took with Mail). No joy, I still have the same problem. I even restored one of my inboxes via Time Machine and the same issue with loading continues.
    I am using ML 10.8.2. I have a combination of IMAP accounts (work) and POP accounts (personal). The issue of loading occurs irrespective of the account.
    I am baffled and am now considering migrating to either Thunderbird or Postbox 3 to try and solve my problem. I prefer to stay with Mail. I should note also that I am using MailTags with Mail (http://www.indev.ca/MailTags.html), although I have not used any of the features. I upgraded to ML from SL about 2 weeks ago. It was very smooth and there appear to be no issues (not sure how helpful this is and probably not at all related to this issue).
    Any suggestions much appreciated!

    Maybe these will help:
    https://discussions.apple.com/message/17677533#17677533
    https://discussions.apple.com/message/18324129#18324129
    https://discussions.apple.com/message/18203126#18203126

  • How can I select to answer a mail with or without the message

    Hello
    When a mail is received and then opened, I have the options to answer to the sender or to all. In the account preferences, I can specify if the original message is copied or not. This option applies to ALL the answers. How can I choose when editing a mail if I want the message to be copied or not ?
    Kind regards
    JP

    This is the easiest method I have found that will resolve your issue.
    'Tools' > 'Account Settings' > 'Composition & Addressing' for the maill account
    or
    'menu icon' > 'Options' > 'Account Settings' > 'Composition & Addressing' for the mail account.
    deselect / do not select 'Automatically quote the original message when replying'.
    Click on OK to save changes.
    To send a 'Reply' with no original message, simply click on 'Reply' button.
    To send a 'Reply' with all or part of original message.
    Highlight the section of the message or all of the message and then click on 'Reply' button

  • Yosemite apple mail select all messages in conversation

    It appears that
    Mail/View/Select/All Messages In This Conversation
    no longer works. The message list UI appears to indicate there are multiple messages in a conversation (they are highlighted, but not selected), but the above listed menu item is greyed out, and using the keyboard shortcut (cmd-shift-k) does nothing.
    Is there a fix for this?
    Ron

    Send Apple feedback. They won't answer, but at least will know there is a problem. If enough people send feedback, it may get the problem solved sooner.
    Mail Feedback

  • Dragging to select multiple messages in Mail 6.0 and OS 10.8

    With recent software updates, there no longer seems to be a way to select multiple messages other than shift-click. I have always just dragged to select a number at once that I need to delete or move for one reason or another, which is much faster. what happened to the drag to select multiple messages in recent mail and OS 10.8 incarnations
    Thanks

    https://discussions.apple.com/message/19031608#19031608

  • Mail command in script hangs and does not release control to calling script

    Hello folks,
    I am running in a situation which I haven't seen before.
    Main script calls function which executes another script.
    No matter which statement is the last in called script, it hangs on the last line and does not return control to main script.
    I tried to call another script not within the function - it is the same result.
    Can you help please.
    Below example of code:
    --- Main script:
    function checksum
    set -x
    /sybdump/ukgoald/scripts/egrep_expr1
    ##MAIN --- call to script script execution which runs mail command
    checksum
    ---- trace execution of called script:
    + read A B RF_FULL_NAME
    + print
    + /usr/bin/mailx -s Checksum Report [email protected]
    + 0< /sybdump/ukgoald/dump1/egrep_expr1.log3
    + print
    + return 0
    Edited by: ge**** on Dec 14, 2010 11:29 PM

    Hello folks,
    I am running in a situation which I haven't seen before.
    Main script calls function which executes another script.
    No matter which statement is the last in called script, it hangs on the last line and does not return control to main script.
    I tried to call another script not within the function - it is the same result.
    Can you help please.
    Below example of code:
    --- Main script:
    function checksum
    set -x
    /sybdump/ukgoald/scripts/egrep_expr1
    ##MAIN --- call to script script execution which runs mail command
    checksum
    ---- trace execution of called script:
    + read A B RF_FULL_NAME
    + print
    + /usr/bin/mailx -s Checksum Report [email protected]
    + 0< /sybdump/ukgoald/dump1/egrep_expr1.log3
    + print
    + return 0
    Edited by: ge**** on Dec 14, 2010 11:29 PM

Maybe you are looking for

  • Mac shuts down

    I had trouble a few months ago with my mac shutting down or going into sleep mode. Several people gave great advice on things to delete in finder (like cookies and some other things). I need to do this cleanup again but my thread won't come up on my

  • Pass Timestamp Parameter to a SP

    Hi All, How to pass a TIMESTAMP parameter to a Stored Procedure?? For eg i want to pass the sdate value as 2007-08-01 12:00:00 create or replace procedure all_test(sdate timestamp) as v_date varchar2(5) := to_char(to_date(sdate,'dd-mm-yyyy HH:MI:SS')

  • Delete old users/jobs in sm37

    We have some old jobs created in SM37 (R/3 4.7) Some of the people who created the jobs has now left the company. How do I assign the jobs to a another user so we get rid of old names in jobs "created by" column in sm37.

  • Open Every Folder Contained Inside A Folder Automatically ?

    I frequently have to open a folder that may contain dozens of other folders which also need opening. It can be quite boring clicking every disclosure triangle. Is there a quick way to open them all automatically, so that all the contents of the origi

  • To pass parameter values to the object reference of action step in sequence file of teststand programatically using C#.

    //Initialize the Engine             EngineClass myEngine = new EngineClass();             myEngine.LoadTypePaletteFilesEx(TypeConflictHandlerTypes.ConflictHandler_Prompt, 0);             Step myStep = myEngine.NewStep(AdapterKeyNames.DotNetAdapterKey