Numbers '09

I’m running Numbers '09 in Leopard on a G5. Anyone know how to set a variable to the selected cell of table 1 of sheet 1 of window 1? The dictionary doesn’t seem to work.

Hello Adam,

it’s similar to MS Excel. The selection represents a range of cells


tell application "Numbers"
	set selectedCell to selection range of table 1 of sheet 1 of document of window 1
end tell

Thanks, Stefan. The problem is this: the result has the word below followed by something unprintable so I can’t get the properties. Must be an artifact of Leopard on a G5 because the result is the same in either Script Debugger or the Script Editor. I’d prefer the G5 with its two large screens for this rather than my Snow Leopard Intel MBP.

Does this work properly for you?

«class

range selection has a couple of properties, for example


tell application "Numbers"
	set theRangeIdentifier to name of (selection range of table 1 of sheet 1 of document of window 1)
	--> "A1:C4"
end tell

This is the result of Snow Leopard, I haven’t tested it on my G5

My G5 is dead since a few months but as far as I remember I got the same result than Stephan.

At this time, it was Numbers v 2.0.3.

May you check the way it behave when used in an other user account?

If it behave normally in the alternate account, I guess that the preferences file is corrupted.

In this case,
quit the app
move the prefs file :

:Users::Library:Preferences:com.apple.iWork.Numbers.plist

to the Desktop
restart the app.

Often it’s sufficient to get rid of surprising behaviors.

Yvan KOENIG (VALLAURIS, France) dimanche 2 janvier 2011 23:01:11

On both my Tiger (G5) and Snow Leopard (MacBook Pro) machines, the result returned by Stefan’s script in post #2 looks something like this and is unusable:

However, direct references to properties and elements of the selection range do produce usable results. So, for instance, for Adam’s original query about getting the selected cell (assuming only one cell’s selected):

tell application "Numbers"
	set selectedCell to cell 1 of selection range of table 1 of sheet 1 of document of window 1
	--> cell "A1374" of table "Table 1" of sheet "Sheet 1" of document "Blah.numbers" of application "Numbers"
end tell

Thank you Nigel; your script works nicely for me on both my machines. The key seems to be the addition of the word cell to the front of the command. The command also works properly with “cells of…” returning a list of all cells included in the selection in the order in which they were selected.

I continue to think that there is something odd on your machine.

Here the Stefan’s script behaves flawlessly.

iMac 3.06 GHz Intel Core 2 Duo
macOS X 10.6.5
Numbers 2.0.4

Of course, I run a 10.6.5 updated by a combo updater, not by a delta one (thru Software Update) because the 10.6.2 delta updater didn’t do a complete job.

Yvan KOENIG (VALLAURIS, France) mardi 4 janvier 2011 17:43:46

Thanks, Yvan. That’s interesting.

But given that I’m getting this particular Numbers/AppleScript anomaly on two very different systems, the Numbers software remains the likely culprit.

MacBook Pro 2.53 GHz Intel Core 2 Duo
Mac OS X 10.6.5
Numbers 2.0.4

G5 Dual 2 GHz PowerPC G5
Mac OS X 10.4.11
Numbers 2.0.3

The one thing they have in common is that the iWorks installations on both machines were generated from the same downloaded evaluation file. Maybe there was a fault in that.

Notes:

  1. Yes. I did buy the correct licence to run the software on both machines.
  2. The Numbers version initially installed was 2.0.3. There was a later Software Update update to 2.0.4 for Intel processors, but not for PPC.

Software Update has just updated my SL system to 10.6.6 and Numbers to 2.0.5. The problem with the selection range still persists.

It occurs to me that another workround is to use the ‘a reference to’ operator to get a working reference to the selection range object:

tell application "Numbers"
	set selectedCell to a reference to selection range of table 1 of sheet 1 of document 1
	--> selection range of table 1 of sheet 1 of document 1 of application "Numbers"
	name of selectedCell
	--> "A1374:A1374"
end tell

Works nicely for me on both machines.

Hello Adam

You are using two intel inside machines, Nigel use also a G5 one.

As far as I remember, I never got the described odd behavior on my G5 but as I wrote, now it’s dead.

Yvan KOENIG (VALLAURIS, France) samedi 8 janvier 2011 10:28:09