How can resolve a terminology conflict? - applescript

Apple Mail defines both a class account and a constant account for the rule type property of a rule condition. The Applescript compiler always resolves this collision of the term "account" to the class, making it impossible to do anything with rule conditions that match accounts.
When there's a conflict such as this, how can I specify a constant instead of a class name? Is there a double-angle syntax for enumerated constants? Is there a solution that works for collisions of any type of terms (not just classes & enumerations)?
Examples
Making an "Account" Rule Condition
The goal of the following non-working example is to create a rule condition that will match an account.
tell application "Mail"
set rool to make new rule at end of rules with properties {name:"test", enabled:false}
(* the following ends up creating an 'any recipient' condition, as 'account'
is «class mact»
*)
make new rule condition at end of rule conditions of rool with properties {rule type:account, expression:"Some Account"}
log rule type of last rule condition of rool
-- result: any recipient
(* inspecting the event for the following, «class tacc» produces the proper
record, ({'rtype':'tacc'}), but the rule condition is still an 'any recipient'
*)
make new rule condition at end of rule conditions of rool with properties {rule:«class tacc», expression:"Some Account"}
log rule type of last rule condition of rool
-- result: any recipient
end tell
Comparing
The goal of the following is to test whether a rule condition has rule type account. For it, first create a rule in Mail.app's preferences named "Account" with a single condition that matches some account.
tell application "Mail"
set acctType to rule type of first rule condition of rule "Account"
log acctType is account
-- result: false
log acctType is «class tacc»
-- result: false
end tell
My earlier question "How can I access a property that has the same name as class but different event code?" is similar, but only covers conflicts between class and property names. Moreover, the solution for it (using «class ...») works for properties, but not for other types of collisions.

One work-around is to define an account type variable referring to the enumeration constant outside of the tell application "Mail" block:
set theAccountType to «constant eruttacc»
tell application "Mail"
set rool to make new rule at end of rules with properties {name:"test", enabled:false}
set theCond to make new rule condition at end of rule conditions of rool with properties {rule type:theAccountType, expression:"Some Account"}
properties of theCond
end tell
See also the Raw code reference, which shows the «class ...», «constant ...» and «event ...» raw code forms.

Having experimented with your code for a while, I don't see any solution – this name ambiguity appears to be an oversight on Apple's part.
There is, however, a simple workaround to this: copy the rule type you need from an existing rule ("dummy").
-- "dummy" was created manually to copy rule types from
set rtype to (rule type of last rule condition of rule "dummy")
set rool to make new rule at end of rules with properties {name:"test", enabled:false}
set rcond to make new rule condition at end of rule conditions of rool with properties {rule type:rtype, expression:"~/Library/Mail/IMAP-john.doe#example.com"}
-- test it:
properties of rcond

Related

How can we get the value of textbox in QTP?

I am executing the automated test scripts in UFT 12.5 I am new to UFT. Not very familiar with codes.There is an edit box wherein i have to type the value "S05292". Example:
Browser(Browsername").Page("Pagename").WebEdit("ctl00$ConBody$txtPDNumber").Set "S05292"
The problem is my script fails at this step and does not type the value. Can somebody provide me with a solution which is easy to understand. I tried the below two methods
Method (1)
a=Browser().page().webedit(ctl00$ConBody$txtPDNumber).getroproperty("value")
if a=="S05292" then
msgbox ("displayed message is S05292")
else
msgbox ("msg is not S05292")
end if
Method (2)
x = Browser("Browsername").Page("Pagename").Webedit("ctl00$ConBody$txtPDNumber").GetROProperty("value")
msgbox x
The error message that displays is
Cannot identify the object "ctl00$ConBody$txtPDNumber" (of class WebEdit).
Verify that this object's properties match an object currently displayed in your application.
Use the Object Spy to get the properties of that text box at run time and then make sure they match up to the properties of that text box in your object repository that you defined. Perhaps that don't match up or you didn't uniquely identify that text box.
If you don't want to use an object repository then you have to pass it a property at run time to uniquely identify it. Some thing like:
Browser().page().webedit("developer name:=PDNumber").
Instead of a .set you can do a .type to set/type the value into the text box

Applescript for mail rules

I have created a rule that messages move into a subfolder when they according to certain criteria.
Additionally, I have saved in this rule an AppleScript that this mail copied subsequently into an DMS.
It is working.
My problem is, that the name of the subfolder is (for now) not passed to the script. It contains only "INBOX":
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with theMessage in theMessages
set nameAccount to name of mailbox of theMessage # here is the problem !
try
tell theMessage
— at this point get the data out of the mail
end tell
tell application id „DMS“
— here the data will save to the dms
end tell
end try
end repeat
end tell
# end try
# end tell
end perform mail action with messages
end using terms from
How do I get the name of the destination folder from the active mail rule?
Instead of the name get the whole mailbox object, it contains the actual reference in the folder hierarchy, to create a subfolder you need the reference anyway.
set theMailbox to mailbox of theMessage
PS: the tell application "Mail" block is not needed, the using terms block is sufficient to evaluate the terminology.

Select a type of sender for email with wildcard

I would like to send an email with applescript. This script will be used on a few computers and the email should be sent by a certain type of account containing "mynetwork.com" in the email address.
Is there a way to automatically select the computer email account containing "my network.com" ? Obviously the wildcard * is not working see code below
property faxboxEmail : {"fax#opilbox.com"}
property theNumber : ""
property theContent : ""
property theSender : "*#mynetwork.com"
tell application "Mail"
set newMessage to make new outgoing message with properties {visible:true, subject:theNumber, content:theContent, sender:theSender}
tell newMessage
make new to recipient with properties {address:faxboxEmail}
end tell
end tell
The sender address for accounts in Mac OS X Mail are stored in the sender addresses property in an account. So, technically what you want is something like get account whose email addresses ends with "#mynetwork.com". However, the email addresses property is a simple list, and AppleScript doesn’t have dynamic searches into lists like that.
However, the number of accounts on any personal computer should be fairly small, so looping through them shouldn’t be a problem.
property faxboxEmail : {"fax#opilbox.com"}
property theNumber : "Nine"
property theContent : "Hello, World"
set foundAddress to false
tell application "Mail"
repeat with potentialSender in accounts
tell potentialSender
repeat with potentialAddress in email addresses as list
if potentialAddress ends with "#mynetwork.com" then
set foundAddress to true
exit repeat
end if
end repeat
end tell
if foundAddress then
exit repeat
end if
end repeat
if foundAddress then
set senderName to full name of potentialSender
set senderAddress to senderName & " <" & potentialAddress & ">"
set newMessage to make new outgoing message with properties {visible:true, subject:theNumber, content:theContent, sender:senderAddress}
tell newMessage
make new to recipient with properties {address:faxboxEmail}
end tell
end if
end tell
You may also find it useful to look at the properties of each account, using something like:
tell application "Mail"
--or “account 1”, “account 3”, etc., up to the number of accounts
get properties of account 2
end tell
If you run that and then look in the results pane, you’ll see all of the properties, including the email addresses property. If your script isn’t doing what you expect it to do, post not just the script, but also the values of the property you’re looking at, in this case the email addresses property. You will probably want to use a test computer with fake example.com, example.org, and example.net email addresses, so as not to expose real email addresses to harvesters.
You also may find it easier to build your scripts from the ground up. For example, in this case, you would want to write a script that sends a hard-coded email from a hard-coded sender. Only once that aspect of the script is working, would you want to add the wrinkle about searching for a dynamic sender. This will simplify your programming process by making each task smaller, and will also make it more obvious where the code is going astray.

How to provide AppleScript support to 'make new' element with one of its own elements

I am using the 'newScriptingObjectOfClass…' method within my application delegate's class in order to accommodate core data. I can 'make' the container element 'level' just fine, however I haven't a clue how to 'make' the element with one of its own elements. In order to make a new 'unit'--an element of 'levels'--I have to refer back at the containing 'level', which is circular logic.
Here's what seems to be the right way to create my new level, however the 'make' command does not provide the term 'element' as a parameter term for 'level' element, 'unit'.
tell application "SpellAnalysis"
make new level with make new element unit
end tell
Here's what my 'sdef' file shows:
level n : Application levels collection
elements
contains units; contained by application.
unit n [inh. level] : Level's unit collection syn unit
elements
contains sections; contained by levels.
Also noteworthy is that my KVC method is never called from the 'newScriptObjectClass…' method when I successfully make a new 'level' (without a contained 'unit'):
- (void)insertObject:(id)entry inLevelObjectsAtIndex:(NSUInteger)index {}
This compiled for me:
tell application "SpellAnalysis"
((make new level with «class») make new element with unit) // syntax 1
((make new level in class) make new unit with element) // syntax 2
end tell
end tell
you'll likely need to tweak it a bit, but that's the general idea for syntax. when i tried your example i got:
'expected “into”, variable name, class name, other parameter name or
property but found command name.'

AppleScript move message to mailbox with Rules in Mail

I looked and looked but couldn't find an answer to this seemingly simple question (I'm also new to AppleScript). Basically, I just want a script that sets up a Rule and moves messages to mailbox "Foo" (a Mailbox in my IMAP account). Here's what I have:
tell application "Mail"
set newRule to make new rule at end of rules with properties {name:"Foo Internal", enabled:true}
tell newRule
make new rule condition at end of rule conditions with properties {rule type:any recipient, expression:"internal_foo#foo.com", qualifier:does contain value}
set move message to mailbox "Foo"
end tell
end tell
I've tried various combinations of this line...
set move message to mailbox "Foo"
...including specifying the IMAP account, setting it to a variable, and so on. I'm not a programmer but I really want to script these rules cause I setup rules all the time at my job. Any help?
Your script fails because of two things:
it omits to set the should move message property of the rule to true, which is needed for a move message action to actually “stick”;
it does not define the object hierarchy of the target mailbox correctly: you will need both the account and the application context, as you are inside a tell block targeting the rule, not Mail.
The following code:
tell application "Mail"
set newRule to make new rule at end of rules with properties {name:"Foo Internal", enabled:true, should move message:true}
tell newRule
make new rule condition at end of rule conditions with properties {rule type:any recipient, expression:"internal_foo#foo.com", qualifier:does contain value}
set move message to (mailbox "Foo" of account "Bar" of application "Mail")
end tell
end tell
will work in Mail 5.2 (stock as of OS X 10.7.4).

Resources