• 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
Re: accessing a property of an object in AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: accessing a property of an object in AppleScript


  • Subject: Re: accessing a property of an object in AppleScript
  • From: KOENIG Yvan <email@hidden>
  • Date: Fri, 7 Nov 2008 14:22:04 +0100


Le 7 nov. 2008 à 04:05, Mark Sanvitale a écrit :

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.


I really don't understand. Here, under 10.4.11 it works flawlessly.

tell application "System Events" to tell process "Safari" to tell menu bar 1 to get name of every UI element

tell application "System Events" to tell process "Safari" to tell menu 1 of menu bar item 3 of menu bar 1 to get name of every UI element

tell application "System Events" to tell process "Safari" to tell menu item 21 of menu 1 of menu bar item 3 of menu bar 1
get properties
set enabled_ to enabled of (get properties)
end tell


log enabled_

The event log returns:

tell application "System Events"
get name of every UI element of menu bar 1 of process "Safari"
{"Apple", "Safari", "Fichier", "Édition", "Présentation", "Historique", "Signets", "Fenêtre", "Aide"}
get name of every UI element of menu 1 of menu bar item 3 of menu bar 1 of process "Safari"
{"Nouvelle fenêtre", "Nouvel onglet", "Ouvrir un fichier…", "Ouvrir une adresse…", missing value, "Fermer", "Fermer", "Fermer toutes les fenêtres", "Fermer toutes les fenêtres", "Fermer l’onglet", "Fermer les autres onglets", "Enregistrer sous…", "Enregistrer sous…", missing value, "Envoyer le contenu de cette page par courrier électronique", "Envoyer un lien vers cette page par courrier électronique", missing value, "Importer des signets…", "Exporter des signets…", missing value, "Format d’impression…", "Imprimer…"}
get properties of menu item 21 of menu 1 of menu bar item 3 of menu bar 1 of process "Safari"
{position:{0, 261}, maximum value:missing value, name:"Format d’impression…", size:{476, 19}, subrole:missing value, class:menu item, minimum value:missing value, enabled:false, selected:false, role:"AXMenuItem", help:missing value, title:"Format d’impression…", value:missing value, entire contents:{}, description:"commande de menu", focused:missing value, orientation:missing value}
get properties of menu item 21 of menu 1 of menu bar item 3 of menu bar 1 of process "Safari"
{position:{0, 261}, maximum value:missing value, name:"Format d’impression…", size:{476, 19}, subrole:missing value, class:menu item, minimum value:missing value, enabled:false, selected:false, role:"AXMenuItem", help:missing value, title:"Format d’impression…", value:missing value, entire contents:{}, description:"commande de menu", focused:missing value, orientation:missing value}
(*false*)
end tell


Yvan KOENIG (from FRANCE vendredi 7 novembre 2008 14:22:02) _______________________________________________
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
References: 
 >accessing a property of an object in AppleScript (From: Mark Sanvitale <email@hidden>)

  • Prev by Date: Re: How can I format an integer ?
  • Next by Date: Re: accessing a property of an object in AppleScript
  • Previous by thread: Re: accessing a property of an object in AppleScript
  • Next by thread: Re: accessing a property of an object in AppleScript
  • Index(es):
    • Date
    • Thread