Re: accessing a property of an object in AppleScript
Re: accessing a property of an object in AppleScript
- Subject: Re: accessing a property of an object in AppleScript
- From: Stan Cleveland <email@hidden>
- Date: Thu, 06 Nov 2008 19:37:01 -0800
- Thread-topic: accessing a property of an object in AppleScript
Title: Re: accessing a property of an object in AppleScript
On 11/6/08 7:05 PM, "Mark Sanvitale" wrote:
This should be a super basic question. Alas, I have spent many hours banging my head against this problem.
I am able to access an object (or element or whatever its official name is) for a menu item. Technically, I do this:
tell application "System Events" to tell process "Safari" to set printMenuItem to menu item "Print…" of menu "File" of menu bar item "File" of menu bar 1
This works. printMenuItem is a reference to the menu item I am after. The dictionary for System Events tells me that a "menu item" is a "UI element" and such things have a bunch of properties. If I execute "return properties of printMenuItem" I can see all the properties that should be there:
{position:{0, 280}, maximum value:missing value, name:"Print…", size:{259, 19}, subrole:missing value, class:menu item, minimum value:missing value, enabled:false, selected:false, role:"AXMenuItem", help:missing value, title:"Print…", value:missing value, entire contents:{}, description:"menu item", focused:missing value, orientation:missing value}
I want to access the enabled property. I eventually discover that I can access a property like so:
return name of (get properties of printMenuItem)
which correctly returns "Print…". Now, I replace name with enabled and I get an error. A few properties work in the above statement (e.g. class, size) but most do not, including my precious enabled property.
What am I doing wrong? Please help me.
You would think that asking such a basic question must mean that I have not attempted any search for the answer. Alas, I have read Apple docs on the AppleScript language, I have searched the mailing lists, I have done innumerable search variations on Google, and I have made more attempts to satisfy Script Editor and its inscrutable language requirements than I dare admit. What I will admit is that AppleScript makes me want to cry. You win AppleScript. You win.
Mark Sanvitale
(formerly believed to be a competent engineer)
Don’t give up, Mark. The failure may be due to how you’re “telling” the application and process. Try nesting things, like below, rather than chaining them together in one long line. The following works OMM (Intel MacBook Pro, OS 10.5.5, AppleScript 2.0.1, Safari 3.1.2):
tell application "System Events"
tell process "Safari"
set printMenuItem to menu item "Print…" of menu "File" of menu bar item "File" of menu bar 1
return enabled of printMenuItem -- false
return size of printMenuItem -- {259, 19}
end tell
end tell
Stan C.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden