Why is there a "set" command in the iWork Suite?

I’m puzzled by the scripting dictionary of the iWork Suite (as shown in Number’s scripting dictionary):

Does anyone know why there’s a set command here and how it’s different from the set used to set properties, variables etc.?

I just noticed that myself (while looking at the recent column count thread) when I saw that the table entry in the numbers suite suggested looking at the iwork suite — so there are two table classes. There are also two document classes — one numbers and one standard.


At least in Numbers 5.1, that is the only `set` command as the standard suite lacks one. Presumably, that lack of mention in the standard suite is an oversight as the command will work outside of a numbers tell statement.

Oddly, there are separate make and delete commands.

No real idea as to why but maybe it’s because they wanted to store spreadsheet data in a special way that was different from the default method. You can insert a table in a Pages document but I don’t think you can insert a sheet so perhaps there is a cross-application element to the decision. I guess this applies to Keynote as well. Both of the other apps have an iwork table class.

I really wish apple would make the occasional effort to provide some documentation support for their applescript implementations. Worse still, I can’t help but think that it negatively affected the (barely existent) applescript documentation for non-apple applications.

You made my day. It’s already one of the worst languages I’ve ever seen not even being specified by a formal grammar (which makes me question whether it even is a language). But OO? I doubt that even Apple believes that, and in the past other people discouraged the idea here, too
Examples:

  • There is no clear concept of methods and which objects they refer to (as we are seeing in this thread and in the one about “how to call do shell script in a tell block and why not”).
  • there are no user definable classes
  • there is no inheritance, i.e. you can’t create a class that inherits and augments for example the Numbers object.
  • there’s no polymorphism

The only thing that I can see vaguely resembling OO ideas is the name class. Just a marketing gag.

Disclaimer: Nor was JavaScript a “real” OO language – it is slowly becoming one, though.

You can’t instantiate an application class. All you ever get is an object. But classes and instantiating them is the key concept of OO. So AS is not an OO language.

Exactly. You get the properties of an object. But suppose I wanted to build a String class on steroids, perhaps adding regular expressions – usually, I’d create a class SuperString that inherits from String. However, I can’t. Nor can I, of course, add properties to it. Just because there’s some syntax resembling OO terminology doesn’t make the stuff OO.
(Both things are, BTW, possible in JavaScript and other OO languages: you can create a new class from an old one, you can add properties and methods to existing classes, and you can instantiate objects of classes).

That has nothing to do with ASObjC which is just an interface to ObjC from AS.

As to examples: Yes, it’s easy to find ObjC examples for old frameworks. Much less for newer ones – try the OCR stuff Apple introduced some years ago. In any case, ObjC is an OO language: it has a clear specification, and it does object-orientation. The same holds for Swift, of course.

That may well be true. Personally, I find Apple’s documentation mostly crap and lacking useful examples. Regardless if we’re talking AS or Numbers or whatever – they just mention the obvious and nearly never go into any depth. Take the original question in this thread: Where is the example on how to use this set command that is particular to the iWork Suite? I couldn’t find anything.

No. An object is not a class. Not even “in other words”. It’s the instantiation of a class. And that’s an important difference.

A class in OOP is something you can inherit from. An object is something you can use. (JavaScript muddies these differences with its “inheritance by prototype”, though). I seem to have said that before.

Look at the text “class” (Class Reference). It has a certain number of properties, for example quoted form of. That’s, by the way, a good illustration of why not even Apple thought about AppleScript as an OO language: otherwise, they’d have provided a method to create a quoted string when needed, not a property. Bad design.

How would you create a class textUTF8 that stores its string in UTF-8 format (as opposed to text’s UTF-16, and inherits all the other behavior of text? You simply can’t.

And everything you wrote is disputing a point I never made – I’m fully aware that AS (and JXA, for that matter) provide reading and writing access to the properties of Object Specifiers (that’s Apple’s term for them, not “object”). But they don’t give you access to the class. And that was the point I made: You never have a class in AS or JXA, you always have only objects (or rather Object Specifiers). Which has nothing to do with OOP, except for a weird naming decision.

I think so, and I don’t see any difference to using set with any other application. It’s just set property to value, in Numbers as in DEVONthink or Safari. I don’t see why Numbers’ dictionary mentions this method at all.

Otoh, if one could use set value of cells of range "A1:B3" to {...}, that would help. But I don’t see that being possible. Or is it?

Of course, I can set the values in a loop, that’s trivial. And bloody slow if you have a lot of values. My point was that it’s simple to get the values in a range with a single set call (you’ll receive a list in that case). But to set several (!) values with a single (!) call is not possible. And the set command in the iWork Suite remains a mystery.

Are you intentionally condescending or just fighting with English?

If it’s a variable or a property doesn’t matter one bit in this context, BTW. It’s the same little set “command”, which

Assigns one or more values to one or more script variables or application objects.

in Apple’s words. That was before they knew that set can also assign to properties :wink:

You guys might find this mildly interesting.

In excel it is possible so presumably apple could implement it if they wished to. Note that it differs depending upon whether you are working with rows or columns.

tell application "Microsoft Excel"
	set sr to range ("A1:A7")
	set vList to {{4}, {5}, {6}, {7}, {5}, {4}, {3}}
	set value of sr to vList
	
	set sr to range ("B1:H1")
	set hList to {5, 4, 3, 1, 2, 3, 4}
	set value of sr to hList	
end tell

Thanks for running the test. The speed is important, and would be more so with larger lists but I’m also interested in being able to change the cells with a single command.

Some individual applications, like excel and omnioutliner, offer this capability for some commands but not all. Sometimes you have to jump through hoops or at least do the non-obvious. In my previous post, it can be seen that for excel, for a single column, you have to go with the odd list of lists.

Meanwhile, in omnioutliner, if you wish to change the font of a batch of rows/cells with a single set font command, you have to use reference to in the specifier. If you specify the range with a direct reference, you would have to rely upon a repeat loop.

This would change the font of any cell in the ‘third’ column that belong to a given set of rows. Again, it both simpler and faster than the alternative.

tell charRow
    set rowTop to (a reference to rows of charRow)
    set colCell to (a reference to cell 3 of rowTop)
    set font of text of colCell to fontName
    set size of text of colCell to fontSize			
end tell
1 Like