Hi, I am trying to do some Applescript work with Numbers, part of iWork 09. It’s a good program in general but has a lot of frustration for scripters, for example the formatting of numbers is for display only, and you can’t “get” the formatted number being displayed through a script any way that I can find.
Anyway, what I’m trying to do is have a row (or field, but row would be better) highlight itself in a color if the length of that field goes over 140 characters. It’s quite hard to do – I can set the text and/or fill color based on actual text in that field, but not on a general calculation allowing me to calculate length. Frustrating to say the least.
Anyone have any suggestions? I’d like it to be “live” as I work rather than the result of a calculation that say, goes through all fields and does something if the length is too much.
Model: Macbook Pro
Browser: Safari 534.13
Operating System: Mac OS X (10.6)
Here is a quick and dirty piece of code which may help.
The important thing is that we can’t set the colors of a cell but that we may set them to a range.
So :
grab the cell’s value
check if it’s length match the condition
If it does, set the color of the range to red
If it doesn’t, set the color of the range to black
set rowNum1 to 18
set colNum1 to 5
tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
tell cell rowNum1 of column colNum1
set maybe to value
end tell
tell range (name of cell rowNum1 of column colNum1)
if (count of maybe) > 8 then
set text color to {65535, 0, 0} -- red
else
set text color to {0, 0, 0} -- black
end if
end tell
end tell
Cool, that works very well. Thanks. Numbers is almost as scriptable as we need it.
One more question I’ve just run across. How would I get the current sheet? I need to know whether I’m on sheet 1 or 2 in order to run my script. Can’t find anything playing with the dictionary, got any ideas?