![]() |
use applescript to create reply-to field in mail.app 1.2.5?
hi guys
just a quicky i hope i have a script that will compose and send a standard message for me now i want to write a similar script but i want to add a reply-to field in the email before it is sent i know this can be done manually i know from the forums that it is possible to create a perminent outgoing reply-to setting but my g/f and others use the same mail app, still using jaguar and dont bother to log out and back in, too much hassle. so i wouild just like to create a "reply-to" setting, by applescript, for specific emails anyone know if this is possible? many thx clive :) |
I don't think you need to use AppleScript at all - just make a new email account (under Mail preferences) that is a duplicate of the current email account and change the "reply to" email address in that copy. You then can choose which account to use when you compose a new message.
|
try this, it adds the Reply to field to a composed message
I was able to add the Reply To field with this code in the compose section of the email. If the Reply To field is already there, then nothing happens. If the Reply To field is not there, then it will add it. The composed message needs to be created before this script is ran. In other words make sure that the compose message is created first in your other script before executing this part of the script.
Code:
thx RLC |
Quote:
Quote:
i think your both talking about "Panther", im still on Jaguar hense mail.app 1.2.5 |
Are you saying that the script doesn't work in Jaquar?
I don't have Jaquar, but you should be able to modify the script slightly and get it to work with a little effort. The main core of the code is
click menu item "Reply-To Header" of menu "View" of menu bar item "View" of menu bar 1. We just have to find the equivalent in Jaquar. Does the mail in Jaquar have the reply to field when you compose mail? I assume that it does since you put this in your original request. I also forgot to mention that this is a GUI script, so for Jaquar, you need the GUI scripting beta installed and then you need to Enable access for assistive devices in the Universal Access of System Preference. thx RLC |
Quote:
o/s 10, to the best of my knowledge, does not enable system events until 10.3 yes the reply to field is available, though like the bcc field, it is not enabled on a new email, you have to manually enable it clive ps, there are loads of little bits of code, not in jaguar but are in panther which can make life so much easier bounce and delete in applescript for mail dont work, it just comes out as junk. also ive not yet managed to run a script from an event within mail, which i read can easily be done in panther. :( |
You can enable system events in Jaquar prior to 10.3
Go to my website and download the
http://homepage.mac.com/WebObjects/F...cty=US&lang=en UIscriptingbeta.sit in the file. You can also download the X11 SDK in order to get system Events working for you. Once you Get system Events working for you in Jaquar, then you should be able to run the code. I used X11 SDK and UIscriptingbeta.sit when I was using Jaquar. It worked for me and it should work for you too. thx. |
Quote:
from what i can gather, X11 is like a whole other o/s, my mac cant handle any more o/s's its old, about 7 years, its primary hard disk is only 6Gig so if i need X11 to run the UI scripting, it just wont fit on my system. ok, downloaded and installed system preferences wont let me check "enable access for assistive devices" it may need a restart though it didnt ask for one on the install. as for the apple script for jaguar, i would guess at something like Code:
click menu item "Add Reply-To Header" of menu "Edit" of menu bar 1i cant restart right now but thought i would let you know where i got to and give you an opportunity to reply cheers clive |
Sorry about that, you do not need X11
You do not need the X11 SDK, I was a little tired when I wrote the last email. X11 is something else. Please tell me that you didn't download it.
You only need the UIscriptingbeta.sit to get system events to work. Please tell me that you downloaded this. Before we proceed, exactly what did you download? Did you down the UIscriptingbeta? If so then you are on the right track. It sounds like you are not able to check "enable access for assistive devices". Does it prompt you for a password? It should prompt you for a password that will allow you to change it. If not, then do you have administrative priveledges on your machine? Let's make sure that you can get this checked before we proceed to look at code. thx RLC |
actually, after i tried other things, including an uninstall and a reinstall, the problem turned out to be that i only had read permission
by changing system events to read write for me, i could then check it in the system prefs file so now i can use system events and i can create a reply-to field with the following code Code:
tell application "Mail"what i cant do yet is type in the text field using system events or set the text field to a variable but i assume that was what part of your code was about so i guess i either need to know what the mail/applescript command is for setting reply-to, or the systemevents/applescript command is ie set value of text field 1 of scroll area 4 of window newMessage to "boo" window newMessage is obvious, ie the window unique id but im not sure about the rest of it but mail and applescript doesnt like it thx for your help so far clive ps like i said, my machine wont take X11, so nope, didnt install or download it |
Explaining more of the code origin.
I am a little confused about your code. First you have thing commented out such as
-- set value of text field 1 of scroll area 4 of window "New Message" to s Let's go over this slowly so that we don't lose each other. The piece of code below -- set value of text field 1 of scroll area 4 of window "New Message" to s is what I actually get from the composed mailed section. I first make new message by clicking command or click file and then new message. Once I have the new message open front and center, I click on the button to show the reply-to field. For me it is located under view and then reply-to header. For you it is located under Edit. Click on this so that the reply-to field is added to your composed mail. Once it is added. Open up your UI element inspector so that you can get the element of the reply-to field. If you don't have the UI element inspector, download it at http://www.apple.com/applescript/uiscripting/02.html Once you download, Open it up and it will be call "UI Element Inspector". Point your mouse in the reply-to field and and hit command+10 to lock it. You will have the path that you need to plug into your code. The UI Element Inspector shows me the following: <AXApplication: “Mail”> <AXWindow: “New Message”> <AXScrollArea> <AXTextField> Attributes: AXRole: “AXTextField” AXRoleDescription: “text field” AXHelp: “(null)” AXValue (W): “” AXEnabled: “1” AXFocused (W): “1” AXParent: “<AXScrollArea>” AXWindow: “<AXWindow: “New Message”>” AXPosition: “x=101 y=614” AXSize: “w=732 h=18” Actions: AXConfirm - confirm This is where I get the menu item 1 of Scroll Area 4 of Window "New Message" What does it say when you do this? Let's stop here and post back with your results, so that we can proceed. I will explain further how this works and where I get the Scroll Area 4 from. thx RLC |
Quote:
Code:
-- set value of text field 1 of scroll area 4 of window "New Message" to s Code:
set newMessage to make new outgoing messagei make a new outgoing message, the message window id goes into the variable newMessage i add a Reply-To header from the Edit menu as you state then i try to set the value of that text window of message id newMessage to the value "boo", its the same as setting "boo" to the value "s" that you use. its the text field 1, scroll area 4 that my apple script doesnt like and its outside the try so i get an error if there is one. as for the rest, im gonna download now, not sure how far ill get tonight though clive :) |
Quote:
Code:
Code:
set s to "boo""text field 1 of scroll area 3" i understand we are targeting the Reply-To field but how you get that from the ui inspector i have no idea but then with apple script, more often than not, the best way to do something is from a working example, trying to understand all of it is not always worth the trouble, i find actionscript much clearer :) if youve a mind to, im ready for lesson one, as to where you get "text field 1 of scroll area 3" from and can i just say, thanks for helping me with this, having system elements back will make coding a lot more like it was in o/s9 :D clive |
ok now im wondering how i can script a bounce of spam using the uiscripting, ive got the following but cant get the keystroke right
Code:
<AXApplication: “Mail”>Code:
Code:
tell window "In — SpamBounce" |
How to get scroll 3 or 4 or whatever.
Sorry, I wasn't able to get back in touch with you sooner as I had an urgent project that I had to deal with at work.
Make sure that your composed mail is front and center where you can clearly see it. At any rate, what you do is open up the element inspector and point your mouse in the reply-to field and and hit command+10 to lock it. When you lock it, the text should turn red in the element inspector. When you lock it, you will also notice another dialog box that pops up. It will say something like "Locked on <AXTextField>. You will notice some items at the right of this box labeled, "goto", "refresh", and "highlight". Click on highlight and the "Reply To" field will be highlighted. Click on the goto box and you will see at least two items; one will read AXParent and the other will read AXWindow. If you click on AXParent, then you will notice that the title <AXTextField> changes to <AXScrollArea>; in addition, the red text in the element inspector has also changed in response to this click. Click on goto followed by AXChildren and you will be back where you started from; this is how I know that this is textfield 1. The point here is that each time you click and element inside of goto, the title of the box and the element inspector will change accordingly. Now make sure that you are at the point where the title reads <AXScrollArea>. Click on goto followed by AXParent. You will notice that the title changes again, this time to <AXWindow "New Message">; the element inspector has also moved up one. In addition, the entire composed message is also highlighted. Click on goto again followed by AXChildren and this time you will see a bunch of elements. The one we are interested in is the scroll area. There will be at least 3 scroll Area elements in your case; you can number them with the topmost being scroll area 1. Click on the scroll areas one by one and eventually you will highlight the Reply to field. The elements are numbered sequentially from top to bottom. Any duplicate element is indexed to the next number. That's it. In this case , it was pretty simple, but sometimes elements can become really embedded within other elements and you may want to use different techniques or applications. One application that comes to mind is prefab. Prefab will allow you to just click on the element and it will automatically give you the path at the click of a button. You can find this at http://www.prefab.com/uibrowser/ I personally don't use it because it is $40.00 and I can find elements rather easy using other methods with a little more time. I hope this helps thx RLC |
keystroke in system events
Quote:
Code:
tell application "System Events"RLC |
Quote:
Code:
ok, ive never made applescript automated in mail in jaguar, but what do you have to save as to run apple script as a rule, in panther. i know there is like a menu item with applescripts in it but i dont have that :( also i have filters for spam so that they all go to their own folder, so if i automated this bounce script i should select the mailbox in question but i believe i can do that in apple script? as for learning how to find the path and decoding it, im going to wait till after 6pm my time before i look at it but thx for the info, ill let you know how i get on :D many thx again clive :) |
im trying to select the right mailbox
the following code kinda works but there are problems Code:
Code:
tell application "Mail"also, as long as i have a mailbox as the main selection, i get no errors, but if i select an email in a mailbox, then i get an error from the first select command any ideas what im doing wrong? many thanks clive :) |
AppleScript in Panther
Quote:
If you want to select a mailbox, then there is probably an easier way to do it then the code that you have written. For example, I have the following key commands for the following mailbox: mailbox key command Inbox command + 1 Out command + 2 Drafts command + 3 Sent command + 4 Trash command +5 Junk command +6 If you want to select a mailbox in your code, then simply write something like the following: Do you have these key commands for the following mailboxes? Does the mailbox you want to target have a command associated with it? Code:
Code:
Code:
Try downloading Prefab, they give you a 30 day free trial, and see if it will be able to help you. In 30 days using Prefab, you will learn a lot to system events in applescript thx RLC |
hi again ron
Quote:
Quote:
4 of them are active email accounts. 2 more are accounts i keep an eye on for family members. i cant just select the Number 1 inbox, it needs to know which of the 15 inboxes to go to :) and in jaguar it doesnt give numbers for those accounts, just Number 1 for the In inbox, all my accounts are nested withing the "In" folder. Quote:
my question was related to do i use the term "click button 1" there seem to be lots of different forms of clicks click radio button click tab to be honest, i dont know if the term click is right, i dont know if im suposed to be clicking something other than a button or a radio button etc. maybe im suposed to be selecting ? switch to? maybe i need to open the account? im just not sure what term is the right term and was hoping you might know? the output seems to indicate it should work, however it just is not switching the accounts. if you have any more thoughts, i would be greatful to hear them many thx clive :) |
Guys,
I'm sorry to butt in, and also if I'm off the thread a little (but this is a very long thread with a lot of code flying around :) ) but in Panther you can select a box so: Code:
property mailbox_to_select : "Add name of mailbox here" |
Quote:
weve actually solved my original problem in spades, but it threw up other things :D your code gives the following from applescript Code:
tell application "Mail"and to be honest ive never seen that term used in applescript for jaguar ive also tried various combinations of and variations on the theme but mail always kicks back an error but thx for trying :) |
My point really is that Mail 1.3.9 has the means to select a mailbox, and I don't know when Mail acquired this function. You could check to see if there's a property "selected mailboxes" in the application or viewer class in the Mail AS Dictionary for the version you have.
The same script without 'as reference' works on my machine - can't remember why it was in the script that snip of code came from. |
invoke a message
Quote:
[/code] tell application "Mail" perform mail action with messages of account "roncross@cox.net" check for new mail end tell -- I haven't tried this code so not sure if it will work. However, there are ton -- of information. Check macosxhints and the other forum for an idea on how this works. [code] You can then open up mail preferences, go to rules. Click on Add rules. Give it a description and fill out the text field part. Notice, where it says Perform the following actions. Click on this and there will be a section that says run applescript. Click on that and select the applescript that you want. It will be invoke, the next time the rule apples to your case. Quote:
|
Quote:
Code:
tell application "Mail"the as dictionary does have "selected mailboxes" but the error is occuring in the line before clive |
hi Ron
Quote:
im guessing that it depends on what you save an applescript as, not how i add a rule to the rules section. are you trying to tell me that you can save any kind of applescript in panther and it will run regardless, as long as the rules are met ? Quote:
i have non applescript stuff that is much more urgent. so i dont mind trying to solve this on this board and at the speed of email rather than instantly with prefab. you should have all the UI info in the previous posts, im assuming you want the deepest level UI info, the one where you do the clicking or whatever, so here it is Code:
<AXApplication: “Mail”> |
Bingo, Success!!!
Code:
tell application "Mail"i could not have done this without you warmest regards clive :D now i just got to get applescript to automate within mail :p |
Quote:
as long as your rules work, this script should be activated just make sure you set the right path to the applescript you actually want to run Code:
on perform_mail_action(info) |
Running applescript with rules
Quote:
Here is what the help section says about rules in Panther. I have used it and I am able to get it to work. However, I am not sure how this works in Jaquar. Go to mail help and type applescript rules and it may explain to you how it work.... Mail Help in Panther when searching Rule and Applescript Mail offers a wide range of actions that can be triggered when an email message meets the conditions in a rule. An example of a simple rule is one that plays a sound if a message is received with a subject that contains a certain word. Other actions that you can set up include moving or copying messages, bouncing the Mail icon in the Dock, and replying to the message. Sometimes you may need additional flexibility when creating rule actions, or may want to interact with other applications that have AppleScript capabilities. You can use AppleScript rule actions to enable actions by other applications and also to increase the flexibility of the actions that already exist. For example, you could have an incoming message trigger a script that gathers information from the message and enters it into an AppleScript-aware database. Or, you could reply to messages with a custom-tailored message using data gathered from another AppleScript-aware application. After you've written an AppleScript, compiled it, and saved it, you can attach it to a rule. To see an example script and create your own script: Press the Option key and choose Scripts > Sample Rule Action Script. The "Sample Rule Action Script" opens in Script Editor. Near the top you'll see a description of the script. When executed, the script displays a dialog showing the name of the rule being executed, and the subject of the message that triggered the rule. Modify this script to suit your needs, or create a new script. Save it in the following location: Applications/AppleScript/Example Scripts/Mail Scripts. Click the Run button at the top of the window to run your script. Click Next for information on attaching your AppleScript to a rule action. Attaching an AppleScript to a rule action In the previous step, you wrote an AppleScript to use for a rule action. In this step, you attach the script to a rule. To attach the script to a rule: Open Mail, choose Mail > Preferences, and click Rules. Click Add Rule or edit an existing rule. Choose conditions from the pop-up menus. Use the Add (+) button to add conditions. Choose Run AppleScript from the "Perform the following actions" pop-up menu. Click Choose and locate your saved script in the dialog that appears. In the previous step, you saved your script in the following location: Applications/AppleScript/Example Scripts/Mail Scripts. Click Choose File. Click OK to save your rule. If you move your script from the location where you saved it, or if you rename it, your rule will stop working. If you want to move or rename the script, modify the rule to reflect the new location. Here's how rule actions work "behind the scenes": When Mail invokes an AppleScript as a rule action, it looks for a handler named "perform mail action with messages," which receives a list of messages as its direct object, with an optional parameter that specifies the rule being executed. Once you have the rule object and the list of messages, you can access all the properties that are shown in Mail's AppleScript dictionary for these objects. For more information on AppleScript, see www.apple.com/applescript. Open the Script Editor application (in Applications/AppleScript) to see example scripts in various applications, including Mail. Go to the website thx RLC |
Quote:
i dont know what it works either, but it does, and thats the most important thing thx for the info clive |
| All times are GMT -5. The time now is 05:46 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.