The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   OS X Developer (http://hintsforums.macworld.com/forumdisplay.php?f=27)
-   -   use applescript to create reply-to field in mail.app 1.2.5? (http://hintsforums.macworld.com/showthread.php?t=26922)

MasterSwitch 08-15-2004 05:44 PM

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 :)

hayne 08-16-2004 12:46 AM

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.

roncross@cox.net 08-16-2004 03:40 AM

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:


set s to ""
tell application "Mail"
        activate
        tell application "System Events"
                tell application process "Mail"
                        try
                                set value of text field 1 of scroll area 4 of window "New Message" to s
                        on error number error_number
                                click menu item "Reply-To Header" of menu "View" of menu bar item "View" of menu bar 1
                                set value of text field 1 of scroll area 4 of window "New Message" to s
                        end try
                end tell
        end tell
end tell

One other thing is that you can set s to a recipient's email address if you like, so when the Reply to field is added, it will automatically put the recipient's name in that field

thx
RLC

MasterSwitch 08-16-2004 05:47 AM

Quote:

Originally Posted by hayne
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.

Quote:

Originally Posted by roncross@cox.net
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.

thx
RLC


i think your both talking about "Panther", im still on Jaguar hense mail.app 1.2.5

roncross@cox.net 08-16-2004 11:07 AM

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

MasterSwitch 08-17-2004 07:08 PM

Quote:

Originally Posted by roncross@cox.net
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
thx
RLC

system events was a little plugin program i did manage to run in o/s 9
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. :(

roncross@cox.net 08-17-2004 11:02 PM

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.

MasterSwitch 08-18-2004 08:43 AM

Quote:

Originally Posted by roncross@cox.net
Go to my website and download the
UIscriptingbeta.sit.
You can also download the X11 SDK in order to get system Events working for you.

thx.

is it an either or?
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 1
or
                                click menu item "Add Reply-To Header" of menu "Edit" of menu bar item "Edit" of menu bar 1

or some combination there off, the "Add Reply-To Header" is in the Edit dropdown menu, its not in a submenu in edit, so not sure about that second bit of code.

i cant restart right now but thought i would let you know where i got to and give you an opportunity to reply

cheers clive

roncross@cox.net 08-18-2004 10:57 AM

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

MasterSwitch 08-18-2004 11:23 AM

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"
        activate
        set newMessage to make new outgoing message
        tell newMessage
                set visible to true -- or true if you want to see it happen false if not.
                set content to "boo" & " hello"
                set subject to "my new message"
                set sender to "<me@yahoo.com>"
        end tell
       
end tell
set s to ""
tell application "Mail"
        activate
        tell application "System Events"
                tell application process "Mail"
                        try
                                --        set value of text field 1 of scroll area 4 of window "New Message" to s
                                --        set value of text field 1 of scroll area 4 of window newMessage to s
                        on error number error_number
                                --        click menu item "Add Reply-To Header" of menu "Edit" of menu bar item "Edit" of menu bar 1
                                --        set value of text field 1 of scroll area 4 of window "New Message" to s
                        end try
                        click menu item "Add Reply-To Header" of menu "Edit" of menu bar 1
// this gives an error
                        set value of text field 1 of scroll area 4 of window newMessage to "boo"
// end error
                end tell
        end tell
end tell
tell application "Mail"
        activate
        tell newMessage
                set myAddress to "<me@Orange.net>"
                --        make new reply to at end of reply to with properties {address:myAddress}       
// this gives error       
                        set reply to of outgoing message id newMessage to "<me@Orange.net>"
end error
               
        end tell
       
end tell

activate


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

roncross@cox.net 08-18-2004 04:04 PM

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

MasterSwitch 08-18-2004 07:41 PM

Quote:

Originally Posted by roncross@cox.net
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

its commented out because im using applescript direct to mail to make a new message so
Code:

--      set value of text field 1 of scroll area 4 of window "New Message" to s       
your code

Code:

set newMessage to make new outgoing message
                        click menu item "Add Reply-To Header" of menu "Edit" of menu bar 1
// this gives an error
                        set value of text field 1 of scroll area 4 of window newMessage to "boo"
// end error
                end tell

this is just me adapting your code to work with the code i already have
i 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 :)

MasterSwitch 08-18-2004 08:38 PM

Quote:

Originally Posted by roncross@cox.net
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

i get the same as you

Code:


<AXApplication: “Mail”>
 <AXWindow: “New Message”>
  <AXScrollArea>
  <AXTextField>

Attributes:
  AXRole:  “AXTextField”
  AXRoleDescription:  “text field”
  AXHelp:  “(null)”
  AXValue (W):  “boo”
  AXEnabled:  “1”
  AXFocused (W):  “1”
  AXParent:  “<AXScrollArea>”
  AXWindow:  “<AXWindow: “New Message”>”
  AXPosition:  “x=105 y=200”
  AXSize:  “w=640 h=18”
  AXSelectedText (W):  “boo”
  AXSelectedTextRange (W):  “pos=0 len=3”

Actions:
  AXConfirm - AXConfirm

however, with a little trial and error, this code works

Code:

set s to "boo"
tell application "Mail"
        activate
        tell application "System Events"
                tell application process "Mail"
                        click menu item "Add Reply-To Header" of menu "Edit" of menu bar 1
                        set value of text field 1 of scroll area 3 of window "New Message" to s
                end tell
        end tell
end tell

i know how all of it works except the bit relating to
"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

MasterSwitch 08-18-2004 09:29 PM

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”>
 <AXWindow: “In — SpamBounce”>
  <AXSheet>
  <AXButton: “OK”>

Attributes:
  AXRole:  “AXButton”
  AXRoleDescription:  “AXButton”
  AXHelp:  “(null)”
  AXEnabled:  “1”
  AXFocused (W):  “0”
  AXParent:  “<AXSheet>”
  AXWindow:  “<AXWindow: “In — SpamBounce”>”
  AXPosition:  “x=634 y=217”
  AXSize:  “w=91 h=34”
  AXTitle:  “OK”

Actions:
  AXPress - press


Code:




tell application "Mail"
        activate
        tell application "System Events"
                tell application process "Mail"
                                click menu item "Select All" of menu "Edit" of menu bar 1
                                click menu item "Bounce To Sender" of menu "Message" of menu bar 1
                        tell window "In — SpamBounce"
                                tell window "Sheet"
                                        keystroke "Press"
                                end tell
                        end tell
                        click menu item "Erase Deleted Messages" of menu "Mailbox" of menu bar 1
                end tell
        end tell
end tell

activate

so how do i script this keystroke of "return" or "enter" or "press" ?
Code:

                        tell window "In — SpamBounce"
                                tell window "Sheet"
                                        keystroke "Press"
                                end tell
                        end tell

thx clive

roncross@cox.net 08-19-2004 04:55 AM

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

roncross@cox.net 08-19-2004 05:02 AM

keystroke in system events
 
Quote:

Originally Posted by MasterSwitch

so how do i script this keystroke of "return" or "enter" or "press" ?

Code:

tell application "System Events"
keystroke return
end tell

this should do it.

RLC

MasterSwitch 08-19-2004 06:33 AM

Quote:

Originally Posted by roncross@cox.net
Code:

tell application "System Events"
keystroke return
end tell

this should do it.

RLC

Code:


tell application "Mail"
        activate
        tell application "System Events"
                tell application process "Mail"
                        try
                                click menu item "Select All" of menu "Edit" of menu bar 1
                                click menu item "Bounce To Sender" of menu "Message" of menu bar 1
                                keystroke return
                                click menu item "Erase Deleted Messages" of menu "Mailbox" of menu bar 1
                        end try
                end tell
        end tell
end tell
activate

cool, i no longer have to do multiple presses to bounce those anoying spam, thx ron, that is so cool :D
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 :)

MasterSwitch 08-19-2004 10:56 AM

im trying to select the right mailbox
the following code kinda works but there are problems

Code:


tell application "Mail"
        activate
        tell application "System Events"
                click button 1 of row 15 of outline 1 of scroll area 1 of group 1 of drawer 1 of window 1 of application process "Mail"
                tell application process "Mail"
                        tell window 1
                                tell drawer 1
                                        -- or drawer 9
                                        tell group 1
                                                tell scroll area 1
                                                        tell outline 1
                                                                tell row 15
                                                                        click button 1
                                                                end tell
                                                        end tell
                                                end tell
                                        end tell
                                end tell
                        end tell
                end tell
        end tell
end tell
activate

in the output window i get the following

Code:

tell application "Mail"
        activate
end tell
tell application "System Events"
        click button 1 of row 15 of outline 1 of scroll area 1 of group 1 of drawer 1 of window 1 of application process "Mail"
                button "SpamBounce (1)" of row 15 of outline 1 of scroll area 1 of group 1 of drawer 1 of window "In — Maitre (43 unread)" of application process "Mail"
        click button 1 of row 15 of outline 1 of scroll area 1 of group 1 of drawer 1 of window 1 of application process "Mail"
                button "SpamBounce (1)" of row 15 of outline 1 of scroll area 1 of group 1 of drawer 1 of window "In — Maitre (43 unread)" of application process "Mail"
end tell
tell current application
        activate
end tell

it doesnt select mailbox "SpamBounce (1)" but that is the right mailbox
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 :)

roncross@cox.net 08-19-2004 10:35 PM

AppleScript in Panther
 
Quote:

Originally Posted by MasterSwitch

but what do you have to save as to run apple script as a rule, in panther.

I believe that applescript in Panther is very similar to applescript in Jaquar. All the scripts that I developed in Jaquar still work in Panther. There really doesn't appear to be any differences.

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:



tell application "Mail"
        activate
        tell application "System Events"
                key down command
                delay 1
                keystroke "1" -- Use the number that select the mailbox you want
                delay 1
                key up command
        end tell
end tell

In your code, you are doing the same thing twice. In your output window you notice that you have two clicks. So you see, you first did it all on one line with

Code:


  click button 1 of row 15 of outline 1 of scroll area 1 of group 1 of drawer 1 of window 1 of application process "Mail"

and then you did

Code:


tell application "Mail"
        activate
        tell application "System Events"
                tell application process "Mail"
                        tell window 1
                                tell drawer 1
                                        -- or drawer 9
                                        tell group 1
                                                tell scroll area 1
                                                        tell outline 1
                                                                tell row 15
                                                                        click button 1
                                                                end tell
                                                        end tell
                                                end tell
                                        end tell
                                end tell
                        end tell
                end tell
        end tell
end tell
activate

They are the same code. I always prefer the one liner. Since my elements differ from your, I am not sure why it isn't working.

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

MasterSwitch 08-20-2004 08:25 AM

hi again ron

Quote:

Originally Posted by roncross@cox.net
I believe that applescript in Panther is very similar to applescript in Jaquar. All the scripts that I developed in Jaquar still work in Panther. There really doesn't appear to be any differences.

um, im not saying scripts wont run, im saying mail cant envoke them itself, or doesnt seem to be able to. but you can save a script in so many different forms, run time only, application, splash screen etc. maybe you have to save the script a certain way so that mail will pic and envoke it when a set of rules have been met?




Quote:

Originally Posted by roncross@cox.net
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:



tell application "Mail"
        activate
        tell application "System Events"
                key down command
                delay 1
                keystroke "1" -- Use the number that select the mailbox you want
                delay 1
                key up command
        end tell
end tell


this wont work, i have 15 accounts active, some are only being used to have different sending names but most are used for one thing or another.
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:

Originally Posted by roncross@cox.net
In your code, you are doing the same thing twice. In your output window you notice that you have two clicks. So you see, you first did it all on one line with

Code:


  click button 1 of row 15 of outline 1 of scroll area 1 of group 1 of drawer 1 of window 1 of application process "Mail"

and then you did

Code:


tell application "Mail"
        activate
        tell application "System Events"
                tell application process "Mail"
                        tell window 1
                                tell drawer 1
                                        -- or drawer 9
                                        tell group 1
                                                tell scroll area 1
                                                        tell outline 1
                                                                tell row 15
                                                                        click button 1
                                                                end tell
                                                        end tell
                                                end tell
                                        end tell
                                end tell
                        end tell
                end tell
        end tell
end tell
activate

They are the same code. I always prefer the one liner. Since my elements differ from your, I am not sure why it isn't working.

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

yep i know im doing it twice, i like to try different ways of writing code and seeing which i prefer, the one liners do look better but the nested code is easier to decode while im learning "System Events" code. i will have to wait on prefab, i dont have time to concentrait on it, in the past ive downloaded shareware, played with it for like two days, then went back when i next got a chance and found it had expired.
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 :)

bramley 08-20-2004 09:07 AM

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"

tell application "Mail"
        activate
        set thebox to mailbox mailbox_to_select as reference
        tell front message viewer to set selected mailboxes to {thebox}
end tell

I wonder if you can do the same in Jaguar.

MasterSwitch 08-20-2004 10:44 AM

Quote:

Originally Posted by bramley
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"

tell application "Mail"
        activate
        set thebox to mailbox mailbox_to_select as reference
        tell front message viewer to set selected mailboxes to {thebox}
end tell

I wonder if you can do the same in Jaguar.

the more the merrier, i would like to solve this
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"
        activate
        get mailbox "SpamReport"
                "No result was returned from some part of this expression."

the highlighted bit of code was "reference"
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 :)

bramley 08-20-2004 10:58 AM

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.

roncross@cox.net 08-20-2004 11:02 AM

invoke a message
 
Quote:

Originally Posted by MasterSwitch

im not saying scripts wont run, im saying mail cant envoke them itself, or doesnt seem to be able to. but you can save a script in so many different forms, run time only, application, splash screen etc. maybe you have to save the script a certain way so that mail will pic and envoke it when a set of rules have been met?

If you want mail to invoke, then you will have to use something like the following: I haven't try it yet

[/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:

Originally Posted by MasterSwitch


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.

Since I am not really sure what you are clicking. Please send me the UI element information. Most of the time, you are supposed to click. Clicking is what is normally done by a mouse. The UI element inspector will let you know what you have to do. But again, Prefab, will just give the entire applescript at the click of a button. If you are actually trying to get something done now!!! Prefab will not waste your time, it will make you more efficient and get the script written for you faster than you are able to do it manually.

MasterSwitch 08-20-2004 12:43 PM

Quote:

Originally Posted by bramley
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.

without it, i get the following error
Code:

tell application "Mail"
        activate
        get mailbox {"SpamReport"}
                "Mail got an error: NSReceiverEvaluationScriptError: 4"

and it highlights "mailbox mailbox_to_select"

the as dictionary does have "selected mailboxes" but the error is occuring in the line before

clive

MasterSwitch 08-20-2004 01:06 PM

hi Ron

Quote:

Originally Posted by roncross@cox.net
Click on that and select the applescript that you want. It will be invoke, the next time the rule apples to your case.

i can select an applescript in the rules section, but it wont run.
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:

Originally Posted by roncross@cox.net
Since I am not really sure what you are clicking. Please send me the UI element information. Most of the time, you are supposed to click. Clicking is what is normally done by a mouse. The UI element inspector will let you know what you have to do. But again, Prefab, will just give the entire applescript at the click of a button. If you are actually trying to get something done now!!! Prefab will not waste your time, it will make you more efficient and get the script written for you faster than you are able to do it manually.

right now im just trying to automate bouncing and erasing of all the spam that comes in from the various accounts i have set up. its not urgent.
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”>
 <AXWindow: “In — SpamBounce (2 unread)”>
  <AXDrawer>
  <AXGroup>
    <AXScrollArea>
    <AXOutline>
      <AXRow>
      <AXButton: “SpamBounce (2)”>

Attributes:
  AXRole:  “AXButton”
  AXRoleDescription:  “AXButton”
  AXHelp:  “(null)”
  AXEnabled:  “1”
  AXFocused:  “0”
  AXParent:  “<AXRow>”
  AXWindow:  “<AXWindow: “In — SpamBounce (2 unread)”>”
  AXPosition:  “x=57 y=318”
  AXSize:  “w=139 h=16”
  AXTitle:  “SpamBounce (2)”

Actions:
  AXPress - press


MasterSwitch 08-20-2004 01:43 PM

Bingo, Success!!!
 
Code:

tell application "Mail"
        activate
        set myCurrentBox to the selected mailboxes of message viewer 1
        set thebox to {mailbox "INBOX" of account "SpamBounce"}
        tell front message viewer to set selected mailboxes to thebox
delay 2
-- go back to original mailbox
        tell front message viewer to set selected mailboxes to myCurrentBox
end tell

THANKYOU BOTH OF YOU
i could not have done this without you

warmest regards
clive :D

now i just got to get applescript to automate within mail :p

MasterSwitch 08-22-2004 10:02 AM

Quote:

Originally Posted by MasterSwitch
now i just got to get applescript to automate within mail :p

for anyone still using jaguar, and interested in this thread, to automate actionscript in mail, use the following code and save the script as a "compiled script"
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)
        tell application "Finder"
                activate
                display dialog "im about to bounce spam" giving up after 60
                open the file "Users:Shared:Scripts:UtilityScripts:BounceDelete.scpt"
        end tell
end perform_mail_action


roncross@cox.net 08-24-2004 11:01 PM

Running applescript with rules
 
Quote:

Originally Posted by MasterSwitch
hi Ron
i can select an applescript in the rules section, but it wont run.
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 ?

You can as long it is compiled.

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

MasterSwitch 08-25-2004 07:02 AM

Quote:

Originally Posted by roncross@cox.net
You can as long it is compiled.

thx
RLC

hi again Ron :)

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.