• 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: AppleScript-Users Digest, Vol 8, Issue 343
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript-Users Digest, Vol 8, Issue 343


  • Subject: Re: AppleScript-Users Digest, Vol 8, Issue 343
  • From: "Adolf.Peter" <email@hidden>
  • Date: Wed, 03 Aug 2011 15:03:38 +0800

Thanks for your reply.
But I think you said about main menu. My issue is about context menu. Do you have ideas?

Thanks,
Peter


Date: Tue, 02 Aug 2011 15:43:05 +0800
From: "Adolf.Peter" <email@hidden>
Subject: Can't find the menu item of the context menu.
To: email@hidden,
       email@hidden
Cc: email@hidden
Message-ID:
       <CAHCp6DY-0Ohj+9ZmU+bAoFuL=email@hidden>
Content-Type: text/plain; charset="iso-8859-1"

Hi guys,

 I have an issue about accessibility when I write applescript.

1.Open TextEdit at first.
2.Run the script:
--------------------------------------------------------

> tell application "System Events"
>    tell process "TextEdit"
>         -- Active application
>         tell application "TextEdit" to activate
>         -- Open context menu
>         set editbox to UI element 1 of scroll area 1 of window 1
>         tell editbox to perform action "AXShowMenu"
>         -- Get count of menu item in the context menu
>         get count every UI element of menu 1 of editbox
>    end tell
> end tell
>
---------------------------------------------------------
But when I run this script, it failed at  line "get count every UI element
of menu 1 of editbox".

Error:
System Events got an error: Can't get menu 1 of text area 1 of scroll erea 1
of window "Untitled" of application process "TextEdit". Invalid index.


With accessiblity tools, I found the menu is under text area.

What caused this issue? Accessiblity or the script?

Thanks,
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.apple.com/mailman/private/applescript-users/attachments/20110802/334aa17c/attachment.html

------------------------------

Message: 3
Date: Tue, 02 Aug 2011 10:15:11 +0200
From: KOENIG Yvan <email@hidden>
Subject: Re: How to find the menu
To: liste AppleScript US <email@hidden>
Message-ID: <email@hidden">email@hidden>
Content-Type: text/plain; charset="windows-1252"


Le 2 août 2011 à 09:33, Adolf.Peter a écrit :

> Hi guys,
>
>  I have an issue about accessibility when I write applescript.
>
> 1.Open TextEdit at first.
> 2.Run the script:
> ---------------------------------------------------------
> tell application "System Events"
>    tell process "TextEdit"
>         -- Active application
>         tell application "TextEdit" to activate
>         -- Open context menu
>         set editbox to UI element 1 of scroll area 1 of window 1
>         tell editbox to perform action "AXShowMenu"
>         -- Get count of menu item in the context menu
>         get count every UI element of menu 1 of editbox
>    end tell
> end tell
> ---------------------------------------------------------
> But when I run this script, it failed at  line "get count every UI element of menu 1 of editbox".

Here are the handlers which I use for years to trigger menu items and submenus items.

The short versions are for the final scripts, the long ones are to check the name of items for safe.


--[SCRIPT]
--=====
(*
my selectMenu("Pages",5, 12)
==== Uses GUIscripting ====
*)
on selectMenu(theApp, mt, mi)
       tell application theApp
               activate
               tell application "System Events" to tell process theApp to tell menu bar 1 to ¬
                       tell menu bar item mt to tell menu 1 to click menu item mi
       end tell -- application theApp
end selectMenu

--=====
(*
my selectSubMenu("Pages",6, 4, 26)
==== Uses GUIscripting ====
*)
on selectSubMenu(theApp, mt, mi, ms)

       tell application theApp
               activate
               tell application "System Events" to tell process theApp to tell menu bar 1 to ¬
                       tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1 to click menu item ms
       end tell -- application theApp
end selectSubMenu

--=====
(*
useful to get the indexs of the triggered item
my select_Menu("TextEdit", 5, 4) (* Format > Convertir au format xxx *)
*)
on select_menu(theApp, mt, mi)
       tell application theApp
               activate
               tell application "System Events" to tell process theApp to tell menu bar 1
                       get name of menu bar items
                       (*{
                       01 - "Apple",
                       02 - "TextEdit",
                       03 - "Fichier",
                       04 - "Édition",
                       05 - "Format",
                       06 - "Fenêtre",
                       07 - "Aide"}
                       *)
                       get name of menu bar item mt
                       -- {"Insert"}
                       tell menu bar item mt to tell menu 1
                               get name of menu items
                               (* {
                               01 - "Police",
                               02 - "Texte",
                               03 - missing value,
                               04 - "Convertir au format xxx",
                               05 - "Empêcher les modifications",
                               06 - "Adapter à la fenêtre",
                               07 - "Permettre la césure",
                               08 - missing value,
                               09 - "Liste…",
                               10 - "Tableau…"}
                               *)
                               get name of menu item mi
                               --{"Convertir au format RTF"} or "Convertir au format Texte"
                               click menu item mi
                       end tell

               end tell
       end tell -- application theApp
end select_menu

--=====
(*
useful to get the indexs of the triggered item
my select_SubMenu("Numbers", 6, 14, 3) (* Table > Footer rows > 2 *)
*)
on select_SubMenu(theApp, mt, mi, ms)

       tell application theApp
               activate
               tell application "System Events" to tell process theApp to tell menu bar 1
                       get name of menu bar items
                       (*{
                       01 - "Apple",
                       02 - "Numbers",
                       03 - "Fichier",
                       04 - "Édition",
                       05 - "Insertion",
                       06 - "Tableau",
                       07 - "Format",
                       08 - "Disposition",
                       09 - "Présentation",
                       10 - "Fenêtre",
                       11 - "Partage",
                       12 - "Aide"}
                       *)
                       get name of menu bar item mt
                       -- {"Tableau"}
                       tell menu bar item mt to tell menu 1
                               get name of menu items
                               (* {01 - "Insérer un rang au-dessus",
                               02 - "Insérer un rang en dessous",
                               03 - missing value,
                               04 - "Insérer une colonne avant",
                               05 - "Insérer une colonne après",
                               06 - missing value,
                               07 - "Supprimer le rang",
                               08 - "Supprimer la colonne",
                               09 - missing value,
                               10 - "Rangs d’en-tête",
                               11 - "Colonnes d’en-tête",
                               12 - "Bloquer les rangs d’en-tête",
                               13 - "Bloquer les colonnes d’en-tête",
                               14 - "Rangs de bas de tableau",
                               15 - missing value,
                               16 - "Ajuster les rangs au contenu",
                               17 - "Ajuster les colonnes au contenu",
                               18 - missing value,
                               19 - "Afficher tous les rangs",
                               20 - "Afficher toutes les colonnes",
                               21 - "Activer toutes les catégories",
                               22 - missing value,
                               23 - "Fusionner les cellules",
                               24 - "Diviser en rangs",
                               25 - "Diviser en colonnes",
                               26 - missing value,
                               27 - "Répartir les rangs uniformément",
                               28 - "Répartir les colonnes uniformément",
                               29 - missing value,
                               30 - "Autoriser la sélection de bordure",
                               31 - missing value,
                               32 - "Afficher le panneau de réorganisation"}
                               *)
                               get name of menu item mi
                               --"Rangs de bas de tableau"
                               tell menu item mi to tell menu 1
                                       get name of menu items
                                       (* {
                                       1 - "0",
                                       2 - "1",
                                       3 - "2",
                                       4 - "3",
                                       5 - "4",
                                       6 - "5"}
                                       *)
                                       get name of menu item ms
                                       -- "2"
                                       click menu item ms
                               end tell

                       end tell

               end tell
       end tell -- application theApp
end select_SubMenu

--=====
my select_menu("TextEdit", 5, 4)
--[/SCRIPT]

To decide if the the format in use is RTF or Text, I check the status of the bottom one (Tableau…).
It's enabled if RTF is in use,
it's disabled if Text is in use.

I already posted a script switching the format some days ago.


Yvan KOENIG (VALLAURIS, France) mardi 2 août 2011 10:11:41


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.apple.com/mailman/private/applescript-users/attachments/20110802/52bd9470/attachment.html

------------------------------

_______________________________________________
AppleScript-Users mailing list
email@hidden
http://lists.apple.com/mailman/listinfo/applescript-users

End of AppleScript-Users Digest, Vol 8, Issue 343
*************************************************

 _______________________________________________
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: AppleScript-Users Digest, Vol 8, Issue 343
      • From: KOENIG Yvan <email@hidden>
  • Prev by Date: Re: Detecting a keydown or key up.
  • Next by Date: Re: AppleScript-Users Digest, Vol 8, Issue 343
  • Previous by thread: Re: AppleScript controlling Xcode 4.01
  • Next by thread: Re: AppleScript-Users Digest, Vol 8, Issue 343
  • Index(es):
    • Date
    • Thread