• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
accessing a property of an object in AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

accessing a property of an object in AppleScript


  • Subject: accessing a property of an object in AppleScript
  • From: Mark Sanvitale <email@hidden>
  • Date: Thu, 6 Nov 2008 19:05:50 -0800

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)

 _______________________________________________
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

  • Follow-Ups:
    • Re: accessing a property of an object in AppleScript
      • From: KOENIG Yvan <email@hidden>
    • Re: accessing a property of an object in AppleScript
      • From: Paul Berkowitz <email@hidden>
    • Re: accessing a property of an object in AppleScript
      • From: Stan Cleveland <email@hidden>
  • Prev by Date: Re: Delete person in AddressBook
  • Next by Date: Re: accessing a property of an object in AppleScript
  • Previous by thread: Re: Delete person in AddressBook
  • Next by thread: Re: accessing a property of an object in AppleScript
  • Index(es):
    • Date
    • Thread