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