Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Where can we get help with writing an Applescript

I've sort of figured out how to do a couple of Applescripts that work well and send new messages from one of my icloud IDs or the other with the appropriate signature but now I'm trying to figure out if I reply to a message and want to change my sender ID and signature how to do that. I've sort of figured out a way of just replying to a message but that's not very useful as I can just hit cmd-R. The other though has always required a lot of mousing.


I'm terrible at figuring out Applescript.


Kerry

iMac, OS X Mountain Lion (10.8.2)

Posted on May 12, 2013 10:25 AM

Reply
24 replies

May 12, 2013 11:41 AM in response to red_menace

Yes I'm talking about Mail.app.


As an example, this is my script for creating an email with this ID and signature I want to use (icloud) but I'm not sure how you do this on a reply to a message where you change you ID and signature:


tell application "Mail"

activate

set theMsg to make new outgoing message with properties {sender:"<kxxxx.d@icloud.com>", visible:true}

set message signature of theMsg to signature "Kerry"

May 12, 2013 11:53 AM in response to Baby-Boomer-USofA

Hi I've got Applescript 1-2-3 which is the latest and supposedly the best book on Applescript and honestly I just don't get it. Its really way over my head. I can use a lot of automation tools but this just is baffling. I think I've got the syntax down right and it constantly comes back with errors. If I use someone elses script that usually works. However, if I need to modify it slightly well I might eventually get it to work but its a challenge.


Like what I'm trying to do from my first script doesn't strike me as that difficult. I just want to change my email ID (aliase) from one to another with the signature. There's even an example script that comes with Mountain Lion that does all of the stuff except when you go to choose your ID this in the example script doesn't work. So its back to searching the internet for something that is close as I can't get mine to work for the life of me.

May 12, 2013 12:00 PM in response to red_menace

Yes this is the one I fooled with. It works right up to where you choose your email signature and it only allows you to choose what you've setup in Mail.app as your default not your aliases also. I also couldn't figure out from this script how I would apply just the final bit of code Signature and email ID to a reply message sitting there but with the wrong ID and signature chosen.

May 12, 2013 12:16 PM in response to red_menace

OK I guess that's what I did in this script but it is creating a message from scratch. The reply message though might be sitting in front of me, I've written my reply and noticed that its the friends and not business address I use. That's where I can't figure out how I get an Applescript to change the ID and signature like it does with the following for my new outgoing messages:


tell application "Mail"

activate

set theMsg to make new outgoing message with properties {sender:"<kxxxx.d@icloud.com>", visible:true}

set message signature of theMsg to signature "Kerry"

end tell



If I use the above on a reply message it creates a new message. If I try to create a reply script with the signature I want and the ID before I go to reply I can do that I just can't seem to get the message to change the ID and signature without all these scripting syntax errors.

May 12, 2013 1:39 PM in response to Kerry Dawson

It sounds liks you are using the wrong kind of message. Making a new outgoing message will do just that, but if you want to reply to a message you will need to use the reply command and specify the particular message you are replying to. For example, the following will create a reply to the first message in the current selection, then set the sender (the sender needs to be one of your accounts):


tellapplication"Mail"


try

settheMessagetoreply (firstitemof (getselection)) withopening window


onerrorerrmessnumbererrnum-- nothing selected

display alert"Error " & errnummessage"No message selected" & return & "(" & errmess & ")"

errornumber-128-- cancel


endtry


telltheMessage


setsenderto"xxxyyy@icloud.com"


endtell

endtell


You can open the scripting dictionary of any scriptable application to see the classes and commands that it provides, although some (like Mail) are more cryptic than others.

May 12, 2013 2:00 PM in response to red_menace

This worked very well. However, I just need to add in one thing which I can't figure out how to do.


I just need to set the signature for the id I would use. What I did was the following and added that one little line at the end which seems so logical and yet what can I say I'm hopeless at this:


tell application "Mail"

try

set theMessage to reply (first item of (get selection)) with opening window

on error errmessnumbererrnum-- nothing selected

display alert "Error " & errnum message "No message selected" & return & "(" & errmess & ")"

error number -128 -- cancel

end try

tell theMessage

set sender to "ksdawson@icloud.com"

set message signature of theMessage to signature "Kerry Dawson"

end tell

end tell


What that final line is doing is supposed to change the Signature from Kerry which is the default to Kerry Dawson which is my alternate.


What could I possibly doing wrong.

May 12, 2013 2:40 PM in response to Kerry Dawson

I do believe I mentioned how cryptic Mail is - well, this is one of those situations. It doesn't look like you can use the terms to specify the signature inside a message tell statement, although that is normally how you use them.


A tell statement targets the enclosed statements to the object of the tell, for example:

telltheMessage

setsenderto"xxxyyy@icloud.com"

endtell

is equivalent to:

setsenderoftheMessageto"xxxyyy@icloud.com"


It is supposed to be, anyway, and is used a lot when using several statements that refer to the same object. However, trying to use the signature in Mail from within the tell statement results in some strangeness, but it looks like the long form does work:


tellapplication"Mail"


try


settheMessagetoreply (firstitemof (getselection)) withopening window


onerrorerrmessnumbererrnum-- nothing selected


display alert"Error " & errnummessage"No message selected" & return & "(" & errmess & ")"


errornumber-128-- cancel


endtry



setsenderoftheMessageto"xxxyyy@icloud.com"


setmessage signatureoftheMessagetosignature"Signature #2"

endtell

Where can we get help with writing an Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.