I am trying to understand how to use the Dictionary. Specifically I am trying to understand the select command in MS Word. However, searching for this command in the dictionary, I do not find it! I know, however, that it is there and that it does work. Is it simply the case that all available commands are not in the dictionary?
I find it a bit strange that I can e.g. select word 1 of current document, but I cannot select paragraph 1 of current document. Even though a selection object is supposed to be able to contain a paragraph property? As you can probably tell, I am really confused. If someone could please clear this up I would be very thankful.
Learning Applescript has turned out to be a tricky endeavor! There seem to be no good recent books to help. I had a MUCH easer time learning C and C++ so far.
Sorry for the late revival of this thread, but I just realized that I did not understand what you mean. If the “select” command is in the standard suite, shouldn’t it appear in the dictionary when I choose the standards suite?
I find no reference what so ever to the command “select”. The only reason I know about it is because I found some other script using it…
Edit: Perhaps I should mention that I am using the latest Office for Mac (2016?). Could it be that the select command has been deprecated, but still works for backwards compatibility?
Just a courtesy FYI - if you’re using Word 2016, the ‘select’ method has, in fact, been removed. It is no longer in the standard library.
You’ll probably need to figure out the respective object’s equivalent mechanism for getting a handle on the start/end and then manually setting a selection object to those points yourself.
Edit: since I just had to handle this myself. If you’re dealing with a ‘field’, be sure to offset your selection (start -1) and (end + 1) to grab the field start/end delimiters. Otherwise you’ll get “odd” (expected, but odd) behavior like double-nesting fields, etc.
I’m using Obj-C, so I wrote a (bad) utility class to handle this - it asks “do you support ‘select’ ?” - if so, use that (for Word 2011). Otherwise, try to figure out if this is a ‘field’ - if so, get the code, offset the selections, then select. Etc. for the various kinds of objects you might need to handle. Because we can’t ask scripting bridge objects about their class (it blows up), I tried to ask if it supported what seemed like a unique selector for that class. Not an ideal solution, but for a limited number of classes, it seems to work (so far…).
Edit 2: I originally wrote that I was using ASOC. Updated to clarify I’m using the scripting bridge. Thank you, Shane
I don’t want to create an instance of the class - I’d like to simply ask “which class are you?” so I can figure out how to handle selection with the content from the instance sent into the function.
I think I found a better option for my class checking.
I was attempting to use…
to request the class, then using
[wordObjectObject isKindOfClass:[SomeClass class]]
where “SomeClass” was my sdef-generated class name. I think this was the problem. This consistently threw an exception (my understanding is this is something to do with the way the proxy classes work with the scripting bridge?).
Instead, I did the following (which works)
//we have our word object “wordObject”
NSString* wordClassName = NSStringFromClass([wordObject class]);
//this worked fine, so I could get the class name string of the current object
Then I just used the string form to compare.
BUT. What I found interesting was that the string form of the class name was not the name defined in the sdef file (EX: MyCutstomPrefixedWordField) - instead it was something like “MicrosoftWordField”. So - not the class names registered from the emitted sdef header.
The option’s not great, but definitely better than guessing on which selectors are supported and unique to a class.