Page 1 of 1

Applescript Dictionary

Posted: 2016-07-07 14:35:44
by Vanceone
So I've been exploring the Nisus Applescript dictionary, and it's sadly quite lacking. It does not appear that you can access the entire document--only the text of the document. Which eliminates comments, footnotes, text boxes, etc. Is this correct?

Oddly, selecting text in a text box, for instance, is accessible through the selected text property.

I realize, of course, that you can use the Nisus Macro language to get most of this (except text in text boxes? Why not? Seems baffling there is no API to reach that text, short of selecting the entire contents of a text box manually). But I would prefer to use applescript in my applescript, if that makes sense. Less "jumping" problems.

So is there a way to access the entire document via Applescript?

Re: Applescript Dictionary

Posted: 2016-07-07 15:16:40
by phspaelti
Hello Vanceone,

The main key is that the Nisus dictionary has the command Do macro command with macro which allows you do/get anything you want. I'd have to think more how to do specific things, but you can certainly use a macro command to select what you want and then use the get selected text to get it into Apple Script for example. If you want to affect the Nisus document I'd generally use a Nisus macro (embedded in a Do macro command with macro command), or if it's more complex, just write a Nisus macro and then trigger that in the same way.

Text in text boxes is just as accessible as any other text in Nisus.

If you are having trouble achieving something, you might want to let us know what you are trying to do.

Re: Applescript Dictionary

Posted: 2016-07-08 08:29:21
by Vanceone
Certainly. What I'm trying to do is build a more advanced templating system with conditional logic and repeat loops built into the document itself; for document automation. Think mail merge on steroids. Of the Mac word processors, only Word and Nisus really seem to have the advanced scripting to allow for this to happen; Pages maybe can do something like this as well, but not sure.

I asked earlier about text boxes and creating them via script; this appears to be impossible. Thus, I don't see any way of using a text box in a template system. That's why I was looking at Applescript; GUI scripting might have an advantage here by programmatically clicking on various menu boxes, etc.

More generally, I was hoping to implement a template language like Django in Nisus and Word. I work in the Legal industry, and Document automation is a use case that is pretty well dominated by HotDocs on the PC side, but nothing is available for the Mac. This is absurd, since Applescript is quite powerful and has been around for decades. Nisus and Word (and wordperfect, back in the day) are eminently capable of doing this.

Ultimately I was planning on building a complete system that relied on templates, and was also on the iOS devices to actually run the template and insert the customer data into the template. This requires an app outside of Nisus, since Nisus does not have the ability to create a "wizard" style information gathering system, as far as I can tell. Thus, creating such a GUI requires an outside app, and then integrating the data with the template. Applescript is born for this kind of thing (mashing multiple apps together), which is why I was investigating it.

I've experimented and have discovered that you can, using ApplescriptObjC (which under Yosemite and later actually works everywhere a script can run, including Applescript run by Nisus Writer --very exciting!), actually communicate with a third party application that can receive distributed NSNotifications; thus sort of bypassing the Sandbox to a small extent. I've also discovered that if you add an Applescript scpt file to the Nisus Macro Menu, Nisus can run it directly. This sets up the possibility to write a 3rd party application that targets both Nisus Writer and any other app, and communicate with that app from Nisus via distributed NSNotifications; and then that app can do the "heavy lifting" as it were to talk to Nisus and the other app.