NWP 2.1 Sandbox Breaks AppleScript

Everything related to our flagship word processor.
Post Reply
hatchmo
Posts: 99
Joined: 2004-03-01 10:35:56
Location: Cotati, CA

NWP 2.1 Sandbox Breaks AppleScript

Post by hatchmo »

I love the new version and many of its features.
However, I am unable to solve an issue with some AppleScripts that call on Nisus templates. After NWP 2.1 moved the file templates to ~/Documents/Nisus Documents/Templates/, my scripts are interrupted with this error:

The file "Nisus New File" could not be opened.
permission was denied: ~/Documents/Nisus Documents/Templates/Nisus New File.dot [NSCocoaErrorDomain - code 257]:
~/Documents/Nisus Documents/Templates/Nisus New File.dot

And Nisus Writer hangs with this message in the frontmost window’s status bar:
"Running Macro 'Unsaved Script'"

Any suggestions?
Thanks.
Richard Hart
Al Hatch
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: NWP 2.1 Sandbox Breaks AppleScript

Post by phspaelti »

Yes, Sandbox breaks AppleScript. What use are you making of AppleScript?

If you are using AppleScript to access other applications, you will have to rewrite things to use them as a service. Having a Nisus Macro call AppleScript with a "Run AppleScript" command will no longer work (in the majority of situations).

Otherwise it would seem best to use the Nisus Macro Language, if possible, and drop the use of AppleScript altogether.
philip
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: NWP 2.1 Sandbox Breaks AppleScript

Post by martin »

Philip is correct, now that Nisus Writer Pro (NWP) version 2.1 is sandboxed, the use of AppleScript has been restricted. You might read this thread which includes a detailed discussion on the matter a few posts down.

Please let us know what your macro is trying to accomplish exactly. We should be able to figure out a way to accomplish the same in NWP 2.1 using either the Nisus macro language, or an AppleScript that is invoked externally.
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: NWP 2.1 Sandbox Breaks AppleScript

Post by Vanceone »

This actually doesn't sound like an Applescript error. That folder is a Nisus folder; it sounds more like part of the file system sandbox is being tripped instead of an Applescript error (If Nisus can read it, so should any Applescripts Nisus runs). Perhaps there's an issue with the macro's getting access to that particular sandboxed folder?
hatchmo
Posts: 99
Joined: 2004-03-01 10:35:56
Location: Cotati, CA

Re: NWP 2.1 Sandbox Breaks AppleScript

Post by hatchmo »

martin wrote:Please let us know what your macro is trying to accomplish exactly.
All of my AppleScripts are external to Nisus Writer Pro. Two of them join a number of messages in Outlook and in Mail, then pass the clipboard to NWP.

Code: Select all

...		set the clipboard to outlookMessages
	end tell
end dumpMessages

on clipboardToNisus()
	global outlookMessages
	try
		tell application "Nisus Writer Pro"
			activate
			set outlookDump to "/Users/richard/Documents/Nisus Documents/Templates/Nisus New File.dot"
			open outlookDump...
Everything after this works fine. AppleScript tells NWP to paste the clipboard, then to move the pointer to the start of the new document, set the font, etc. The problem is the line ending with Nisus New File.dot. That's the one that throws the permissions error.
Al Hatch
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: NWP 2.1 Sandbox Breaks AppleScript

Post by Vanceone »

Okay, I'm not sure on the permissions bit (I'd recommend selecting the file in the Finder, doing a "Get info" command and making sure the permissions are set to everyone read/write/create on it), but my suggestion is to change your approach.

Instead of trying to open the template file, just create a new document:

Code: Select all

tell Nisus Writer Pro
Create new file

.... paste the clipboard, etc.

end tell
You are creating a new file the hard way, and it's not a surprise it is breaking. Now, if you have a specific template in mind for Nisus to be opening, then I'd suggest using Nisus' macro language to do that (Direct support in Nisus for Applescript is limited; frankly I'm amazed that you are accomplishing what you are with pure Applescript).
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: NWP 2.1 Sandbox Breaks AppleScript

Post by phspaelti »

hatchmo wrote:
martin wrote:Please let us know what your macro is trying to accomplish exactly.
All of my AppleScripts are external to Nisus Writer Pro. Two of them join a number of messages in Outlook and in Mail, then pass the clipboard to NWP.

Code: Select all

...		set the clipboard to outlookMessages
	end tell
end dumpMessages

on clipboardToNisus()
	global outlookMessages
	try
		tell application "Nisus Writer Pro"
			activate
			set outlookDump to "/Users/richard/Documents/Nisus Documents/Templates/Nisus New File.dot"
			open outlookDump...
Everything after this works fine. AppleScript tells NWP to paste the clipboard, then to move the pointer to the start of the new document, set the font, etc. The problem is the line ending with Nisus New File.dot. That's the one that throws the permissions error.
Using "Open" in an AppleScript like this will not work. It will give you a permissions error. Ideally one should be able to precede this with a "File.requireAccessToFileAtPath" command, but this has not worked for me. It seems to be a bug.
philip
Vanceone
Posts: 211
Joined: 2013-05-03 07:06:31

Re: NWP 2.1 Sandbox Breaks AppleScript

Post by Vanceone »

According to the release notes for Nisus 2.1.1 (that is in Beta, so it's not been publicly released yet); this issue may be fixed.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: NWP 2.1 Sandbox Breaks AppleScript

Post by martin »

phspaelti wrote:Using "Open" in an AppleScript like this will not work. It will give you a permissions error. Ideally one should be able to precede this with a "File.requireAccessToFileAtPath" command, but this has not worked for me. It seems to be a bug.
That is correct: all of the File commands in Pro 2.1 related to sandbox access did not function via AppleScript.
Vanceone wrote:According to the release notes for Nisus 2.1.1 (that is in Beta, so it's not been publicly released yet); this issue may be fixed.
That's also true. We fixed the problem of using File commands via AppleScript in the just released public beta of Pro 2.1.1. You can download the Pro 2.1.1 beta here. The beta should be relatively stable, since the number of changes is small and focussed, but all the usual warnings about running beta software apply. We expect to have a proper release soon enough.
hatchmo
Posts: 99
Joined: 2004-03-01 10:35:56
Location: Cotati, CA

Re: NWP 2.1 Sandbox Breaks AppleScript

Post by hatchmo »

Thanks, everyone, for the help and suggestions here. They have led me to a working rewrite of my AppleScripts. And I appreciate Nisus for spending the time and effort even on these "special" cases.
Al Hatch
Post Reply