How can I add a Title to Numbers Chart, please?

I’ve got my Chart format in Numbers down pat with help from this forum, but I’d like to add a Title to each chart.

The charts don’t show up using the UI Browser app, so I’m at a loss as to how to go about it.

The attached code creates a chart, and selects it, but how to address the ‘Title’ field?

Regards

Santa


tell application "Numbers"
	activate
	tell document 1
		tell sheet 1
			tell current application to delay 0.1
					tell table 1
						tell current application to delay 0.1
						set thisRangeName to "A:B"
						set selection range to range thisRangeName
						tell current application to delay 0.5
					end tell
				tell application "System Events" to tell process "Numbers"
				tell current application to delay 0.2
				click menu item "Chart" of menu 1 of menu bar item "Insert" of menu bar 1
				set x to 0
				repeat until exists menu 1 of menu item "Chart" of menu 1 of menu bar item "Insert" of menu bar 1
					tell current application to delay 0.1
					set x to x + 1
					if x ≥ 40 then exit repeat
				end repeat
				try
					click menu item (my theNumbersGraphType) of menu 1 of menu item "Chart" of menu 1 of menu bar item "Insert" of menu bar 1
				on error
					try
						click menu item "3D Stacked Column" of menu 1 of menu item "Chart" of menu 1 of menu bar item "Insert" of menu bar 1
					on error
						click menu item 1 of menu 1 of menu item "Chart" of menu 1 of menu bar item "Insert" of menu bar 1
					end try
				end try
				tell current application to delay 0.1
				set x to 0
			end tell # sheet 1
			repeat until exists chart 1
				tell current application to delay 0.1
				set x to x + 1
				if x ≥ 40 then exit repeat
			end repeat
			set width of chart 1 to (width of chart 1) * 1.8
			tell application "System Events" to tell process "Numbers"
				try
					if value of checkbox "Title" of scroll area 3 of window 1 is 0 then
						click checkbox "Title" of scroll area 3 of window 1
					end if
				end try
				try
					if value of checkbox "Legend" of scroll area 3 of window 1 is 1 then
						click checkbox "Legend" of scroll area 3 of window 1
					end if
				end try
			end tell
		end tell
	end tell
end tell


Model: Late 2014 retina i7, Yosemite
AppleScript: 2.4
Browser: Safari 600.2.5
Operating System: Other

So I guess the answer is ‘You’re out of luck’, eh?

Would be a good idea to post the complete script.
Here it calls a missing handler. It was not a handler but a property

More, trying to help a script written for English language is not easy for non English users.

I edited the script so that it may run on a non English system.

property theNumbersGraphType : 14

tell application "Numbers"
	activate
	tell document 1
		tell sheet 1
			tell current application to delay 0.1
			tell table 1
				tell current application to delay 0.1
				set thisRangeName to "A:B"
				set selection range to range thisRangeName
				tell current application to delay 0.5
			end tell
			tell application "System Events" to tell process "Numbers"
				set frontmost to true
				tell current application to delay 0.2
				log (get name of menu items of menu 1 of menu bar item 5 of menu bar 1)
				(*Feuille, missing value, Saut de colonne, missing value, Numéro de page, Nombre de pages, Date et heure, missing value, Tableau, Graphique, Zone de texte, Figure, Ligne, Surligner, Commenter, missing value, Rangs copiés, Colonnes copiées, missing value, Formule, Équation MathType., missing value, Choisir.*)
				log (get name of menu item 10 of menu 1 of menu bar item 5 of menu bar 1)
				(*Graphique*)
				click menu item 4 of menu 1 of menu bar item 5 of menu bar 1
				set x to 0
				repeat until exists menu 1 of menu item 10 of menu 1 of menu bar item 5 of menu bar 1
					tell current application to delay 0.1
					set x to x + 1
					if x ≥ 40 then exit repeat
				end repeat
				
				log (get name of menu items of menu 1 of menu item 10 of menu 1 of menu bar item 5 of menu bar 1)
				(*Colonnes, Colonnes empilées, Barres, Barres empilées, Ligne, Couches, Couches empilées, Diagramme circulaire, Nuage de points, Mixte, 2 axes, missing value, Colonnes 3D, 
				Colonnes 3D empilées,
				Barres 3D, Barres 3D empilées, Linéaire 3D, Couches 3D, Couches 3D empilées, Circulaire 3D*)
				log (get name of menu item 14 of menu 1 of menu item 10 of menu 1 of menu bar item 5 of menu bar 1)
				(*Colonnes 3D empilées*)
				try
					tell menu bar 1 to tell menu bar item 5 to tell menu 1 to tell menu item 10 to tell menu 1 to click menu item (my theNumbersGraphType)
					--click menu item (my theNumbersGraphType) of menu 1 of menu item 10 of menu 1 of menu bar item 5 of menu bar 1
				on error
					try
						tell menu bar 1 to tell menu bar item 5 to tell menu 1 to tell menu item 10 to tell menu 1 to click menu item 14
						--click menu item 14 of menu 1 of menu item 10 of menu 1 of menu bar item 5 of menu bar 1
					on error
						tell menu bar 1 to tell menu bar item 5 to tell menu 1 to tell menu item 10 to tell menu 1 to click menu item 1
						--	click menu item 1 of menu 1 of menu item 10 of menu 1 of menu bar item 5 of menu bar 1
					end try
				end try
				tell current application to delay 0.1
				set x to 0
			end tell # sheet 1
			repeat until exists chart 1
				tell current application to delay 0.1
				set x to x + 1
				if x ≥ 40 then exit repeat
			end repeat
			set width of chart 1 to (width of chart 1) * 1.8
			tell application "System Events" to tell process "Numbers"
				log (get name of checkbox of scroll area 3 of window 1)
				--> {"Titre", "Légende", "Données masquées"}
				try
					if value of checkbox 1 of scroll area 3 of window 1 is 0 then
						click checkbox 1 of scroll area 3 of window 1
					end if
				end try
				try
					if value of checkbox 2 of scroll area 3 of window 1 is 1 then
						click checkbox 2 of scroll area 3 of window 1
					end if
				end try
			end tell
		end tell
	end tell
end tell

It builds the chart with the default title “Titre” but I found no way to get the coordinates of this object so that we may select it to edit it.

I will continue to search but I have quite no hope.

In Numbers '09 the dictionary totally ignored chart objects.
In Numbers 3.x the object is defined.
In Numbers 4.x with a bit of luck we will be able to work upon such item.

I tried to select the title with :

tell application "Numbers" to tell document 1 to tell sheet 1
	set {chartX, chartY} to position of chart 1
	set chartWidth to width of chart 1
end tell
tell application "System Events" to tell process "Numbers"
	set {scrollAreaX, scrollAreaY} to (get position of scroll area 1 of window 1)
	# I must use these two offsets (off7) to get the coordinates which are given by the application XYPosition.app
	set xOff7 to 21
	set yOff7 to 48
	set Xpos to (scrollAreaX + chartX + xOff7 + chartWidth div 2)
	set Ypos to (scrollAreaY + chartY + yOff7)
	click at {Xpos, Ypos}
end tell
# I installed cliclick for test but it just opens the web page http://www.bluem.net/en/mac/donations/ when I call it
do shell script "/usr/bin/cliclick -dc:" & Xpos & "," & Ypos

Yvan KOENIG (VALLAURIS, France) jeudi 16 avril 2015 09:27:06

G’day, and thanks for trying Yvan. I lodged an ‘Add Feature’ request with Apple Numbers Feedback.

Regards

Santa