Accessing Applescript Script Libraries?

Get help using and writing Nisus Writer Pro macros.
Post Reply
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Accessing Applescript Script Libraries?

Post by Vanceone »

Is there a way to access Applescript Script Libraries from Nisus? I have a Script Library that installed in ~/Library/Script Libraries/ and an applescript file that uses it.

One neat thing about Nisus is that it runs Applescript sctp files directly. But while my script runs fine outside of Nisus, inside of nisus it's not working; and I can only assume it's because Nisus running applescript does not open script libraries?

I hope that's not true, I really do. I'd love to have a large applescript library to use with short and sweet Applescript commands in Nisus code. Particularly since Yosemite you can use applescript-objC code from Applescript running in Nisus.
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: Accessing Applescript Script Libraries?

Post by Vanceone »

Also, how can you pass information to your applescript? Like, say, an array or dictionary?
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Accessing Applescript Script Libraries?

Post by phspaelti »

There are no simple answers here, especially since sandboxing has interrupted a lot of the back and forth that used to be possible between Nisus and AppleScript. In particular Nisus cannot use AppleScript to access other applications.

If your AppleScript is self-contained you can just make it a service, and then it will be available in the Service menu. For more on this see the previous discussion https://www.nisus.com/forum/viewtopic.php?f=17&t=5948

Passing values to AppleScript from Nisus is usually done by constructing a string of the form "set myValue to x" and then running it as an AppleScript.
Another method is to pass values via the clipboard.

If you wanted to pass an array to AppleScript, you could probably use the ".join" command in Nisus, pass it as a single value, and then split it in AppleScript. I've never tried this though.

Going the other way, from AppleScript to Nisus, you usually make heavy use of the "Do Menu Macro with macro" command in AppleScript. My general preference is to write as much of the macro as possible in Nisus, but it really depends on the problem.
philip
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: Accessing Applescript Script Libraries?

Post by Vanceone »

Thanks phspaelti. I kind of thought that was the case. Transferring information back and forth between Applescript and Nisus seems harder than it should be. Also, the "Send Selector" command is very limited, correct? We cannot send any arguments with our selector or use multiple argument selectors?

Among other things, I'm contemplating building a series of custom dialogs. Nisus's macro language cannot do that, so I have to resort to Applescript (and ApplescriptObjC) and pass values back and forth.

Is each call to "Run Applescript" self contained, or does each call stand alone, and I'd have to repeat all setup code?
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Accessing Applescript Script Libraries?

Post by martin »

Vanceone wrote:Also, the "Send Selector" command is very limited, correct? We cannot send any arguments with our selector or use multiple argument selectors?
That's correct, the "Send Selector" command in the Nisus Macro Language cannot pass arguments, or use multiple argument selectors. It was really only intended to allow macros to trigger AppKit action methods like -deleteToEndOfLine:
Is each call to "Run Applescript" self contained, or does each call stand alone, and I'd have to repeat all setup code?
Each call to "Run Applescript" is compiled and run independently via separate NSAppleScript instances, so you'll have to repeat any setup/teardown code.
Bob Stern
Posts: 170
Joined: 2006-03-12 12:32:47

Re: Accessing Applescript Script Libraries?

Post by Bob Stern »

This module loader OSAX might be able to circumvent sandboxing:

http://www.script-factory.net/software/ ... index.html
Post Reply