Trying to script iWork 09

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)

What do you mean by a “field”?

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
			set text color to {0, 0, 0} -- black
		end if
	end tell
end tell

Yvan KOENIG (VALLAURIS, France) samedi 26 février 2011 21:53:35

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?

Go to my iDisk :

Download :

For_iWork:iWork '

It contain a lot of handlers which I wrote during the late year.

I wrote the ones selecting sheet with the help of Nigel Garvey.

Of course, you are free to download other scripts if you want.
No need to reinvent the wheel (mainly when it is free).

Yvan KOENIG (VALLAURIS, France) lundi 28 février 2011 16:20:18