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)

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.