(Copied from ObjC forum, as I’ve been told I posted in the wrong forum, sorry)
I’m trying to set the Graph vertical increment in a Numbers Chart, but can’t click on or select the Text Field for the stepper.
It will accept a value, but I cannot work out how to ˜lock’ the entered value. I’ve tried sending a keystroke, but it still reverts to its old setting.
Any advice please on how I can alter the stepper text field value, and have it ˜stick’.
Regards
Santa
Open this Scriplet in your Editor:
tell application "Numbers"
activate
tell document 1
set maxValue to ""
try
tell sheet 1
tell table 1
set maxValue to 0
repeat with x from 2 to count of cells of column "B"
if value of cell x of column "B" > maxValue then set maxValue to value of cell x of column "B"
end repeat
end tell
end tell
if maxValue > 10000 then
set chartInterval to (maxValue + 10000) div 10000
else
if maxValue > 1000 then
set chartInterval to (maxValue + 1000) div 1000
else
if maxValue > 100 then
set chartInterval to (maxValue + 100) div 100
else
if maxValue > 10 then
set chartInterval to (maxValue + 10) div 10
else
set chartInterval to (maxValue + 1) div 1
end if
end if
end if
end if
end try
end tell # document 1
try
if chartInterval = "" then set chartInterval to "Auto"
tell document 1
tell sheet 1
set width of chart 1 to (width of chart 1)
end tell
end tell
end try
activate
tell application "System Events" to tell process "Numbers"
# tell window 1
tell current application to delay 0.2
click radio button 2 of radio group 1 of window 1
tell current application to delay 0.1
click radio button 1 of radio group 1 of scroll area 3 of window 1
tell current application to delay 1
say (exists text field 3 of scroll area 3 of window 1) --< true
try
click text field 3 of scroll area 3 of window 1
end try
try
select text field 3 of scroll area 3 of window 1
end try
tell current application to delay 0.1
set value of text field 3 of scroll area 3 of window 1 to chartInterval as text ”< works, but doesn't ˜stick'.
# keystroke chartInterval as text
tell current application to delay 0.1
keystroke return
#end tell
end tell
end tell
Why are you using GUI Scripting to set the value of a stepper ?
Assuming that there is one in cell B2 and that there is a slider in C2
This simple piece of code do the job.
tell application "Numbers" to tell document 1
tell sheet 1 to tell table 1
set value of cell "B2" to 85
set value of cell "C2" to 76
end tell
end tell
You just need to know the range used to define both objects.
It would be fine if Numbers was fair enough to give the limits of the range when we ask for the cell’s properties but at this time we must live without this feature.
Yvan KOENIG (VALLAURIS, France) lundi 30 mars 2015 09:42:04
I think Santa has a linked table and graph chart in the same sheet and he wants to set the step interval of an axis in the chart based on the maximum value in column “B” of the table.
What works for me with Numbers 3.5.2 is to set the focus on the text field, set the value, and then move the focus away to another field:
tell application "System Events" to tell process "Numbers"
set frontmost to true
tell window 1
click radio button 2 of radio group 1
tell scroll area 3
click radio button 1 of radio group 1
set focused of text field 3 to true
set value of text field 3 to chartInterval as text
set focused of text field 2 to true
end tell
end tell
end tell
tell application "Numbers"
activate
tell document 1
set chartInterval to "Auto"
try
tell sheet 1
tell table 1
set maxValue to 0
repeat with x from 2 to count of cells of column "B"
if value of cell x of column "B" > maxValue then set maxValue to value of cell x of column "B"
end repeat
end tell
end tell
if maxValue < 12 then
set chartInterval to (maxValue) div 1 # This will need altering if maxValue in not integer
set maxX to (maxValue)
else
if maxValue < 201 then
set chartInterval to (maxValue + 10) div 10
set maxX to (chartInterval) * 10
else
if maxValue < 2001 then
set chartInterval to (maxValue + 100) div 100
set maxX to (chartInterval) * 100
else
if maxValue < 20001 then
set chartInterval to (maxValue + 1000) div 1000
set maxX to (chartInterval) * 1000
else
set chartInterval to (maxValue + 10000) div 10000
set maxX to (chartInterval) * 10000
end if
end if
end if
end if
end try
end tell # document 1
try
tell document 1
tell sheet 1
set width of chart 1 to (width of chart 1) # To select it
end tell
end tell
activate
tell application "System Events" to tell process "Numbers"
tell current application to delay 0.2
click radio button 2 of radio group 1 of window 1
tell current application to delay 0.1
click radio button 1 of radio group 1 of scroll area 3 of window 1
tell current application to delay 0.1
set focused of text field 3 of scroll area 3 of window 1 to true
keystroke (chartInterval as text) & return as text
set focused of text field 1 of scroll area 3 of window 1 to true
keystroke (maxX as text) & return
set focused of text field 2 to true # Unneccessary
end tell
end try
end tell