Sub Menu Syntax Issues

I am new to AppleScript and and trying to start with some simple scripts, but am having a challenge selecting options from sub-menus.

I can select options from main menus such as the following:

tell application "Adobe InDesign CS6" to activate
tell application "System Events" to tell process "InDesign"
	tell menu bar 1
		tell menu bar item "File"
			tell menu "File"
				click menu item "Open..."
			end tell
		end tell
	end tell
end tell

But am having trouble with examples such as the following:

tell application "Adobe InDesign CS6" to activate
tell application "System Events" to tell process "InDesign"
	tell menu bar 1
		tell menu bar item "File"
			tell menu "File"
				tell menu item "New"
					tell menu "New"
						click menu item "Document..."
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

I suspect my syntax is incorrect. Any suggestions of what I may be doing wrong?

Hi,

in my CS 3 version of Indesign the process is also called “Adobe InDesign CS3”.
The 3 dots in Open… are 3 dots in CS 3 but could be also a ellipsis character (⌥; on US keyboard)


activate application "Adobe InDesign CS3"
tell application "System Events"
	tell process "Adobe InDesign CS3"
		tell menu bar 1
			tell menu bar item "File"
				tell menu 1
					click menu item "Open..."
				end tell
			end tell
		end tell
	end tell
end tell

Thank you for your reply. I understand that there is often confusion between 3 dots and an ellipsis. I have tried each, but no success. The process name does not appear to be my issue, as my first example to “Open…” works, bringing up the appropriate dialogue box. It is not until I take it a step further and attempt to select an option from a sub-menu that I have an issue. I find that AppleScript will run (even without errors) however will not launch the dialogue box chosen.

I have tried this schema with other menu options without success, so feel that I am missing something here.

You may try to use these handlers:


my select_SubMenu("Adobe InDesign CS3", 6, 14, 3) # the numeric values are defining :Table > Footer rows > 2 in Numbers

#=====
(*
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)
# mt is the title menu index
# mi is the menu item index
# ms is the	submenu item index

	activate application theApp
	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"
				# Here the instruction triggering the menu item is disabled
				--click menu item ms
			end tell -- menu item.
			
		end tell -- menu bar.
		
	end tell -- System Events
end select_SubMenu

#=====
(*
my selectSubMenu("Pages",6, 4, 26)
==== Uses GUIscripting ====
*)
on selectSubMenu(theApp, mt, mi, ms)
	
	activate application theApp
	tell application "System Events" to tell application 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 selectSubMenu

#=====

The first one is useful to get the exact names of the menu and menu items.
The second one allow us to trigger the submenu from every localized version with a compact code.

Of course, edit the calling instructions to fit your needs.

Yvan KOENIG (VALLAURIS, France) vendredi 14 décembre 2012 15:54:40

Like other Adobe applications Indesign has an UI suite so it’s directly scriptable


tell application "Adobe InDesign CS3"
	tell menu "Main"
		tell submenu "File"
			tell submenu "New"
				select menu item "Document..."
			end tell
		end tell
	end tell
end tell

Stefan - this worked perfectly! Thank you so much. So easy!

Hi. Perhaps you’re doing this just to gain the knowledge of manipulating menu items, however, since you’re a newbie and since the previous respondents didn’t mention it, I’d like to point out that neither of the code examples you posted require UI scripting. You can directly make new documents and open files using built-in commands.

tell application "InDesign CS" to {make document, open (choose file)}

That is interesting. Would you happen to know of a repository of built-in commands for InDesign?

Each application has a dictionary that can be accessed through Script Editor. Shift+Apple(command)+O

I recommend that newbies always start by reading Adobe’s scripting guides for their product. Here is the link for IDCS5, you can search for the later version.

http://www.google.com/url?q=https://www.adobe.com/content/dam/Adobe/en/devnet/indesign/cs55-docs/InDesignScripting/InDesign-ScriptingGuide-AS.pdf&sa=U&ei=HVfLUPP1HYToqwGiiICIAg&ved=0CBkQFjAA&usg=AFQjCNHdS4-p4yc8nQj-i12L8DdrScp_kQ

Ahhh. Thank you, Marc for stepping in on this. I was skimming this thread hoping someone would lead the poster the right direction (and ready to do it myself if need be).

IMO, I would rather call a problem unsolvable than resort to UI Scripting. :stuck_out_tongue: