Mac Sandbox issue opening file with executeProgram('open')

Hi,

currently i get messages from my customers which having trouble to open files on Mac in the Preview app, when the Preview app isn’t started yet.
When the Preview app is already open, there’s no problem opening the files.

Servoy: 7.5.10
Java: 1.8 Update 151
OS: High Sierra (10.13.2)

First i write a pdf-File in the clients temp folder:

var tmpFile= plugins.file.createTempFile(...)
plugins.file.writeFile(tmpFile, blob)

Then i try to open that file:

application.executeProgram('open', [tmpFile.getAbsolutePath()])

When the Preview app is already started, the PDF file will open without problems.
But when Preview is not open i see in the dock for less then a second, that the Preview app tries to start.
The console has the following output when opening the file:

Sandbox: Preview(35168) deny(1) file-read-data /Users/astefan/Library/Application Support/Oracle/Java/Deployment/cache/6.0/bundles

So it seems to be a permission problem in the sandbox.

I also tried to use the “open” command directly in the Terminal - this works!

Does anybody has the same issue? Is there a solution?

The same issue appears when opening a Word document: When Word is already open, no problem…

I noticed that another customer with Java 8 Update 131 has no problem opening these files (still when Preview isn’t open!)
So is it a Java bug?

Thanks!
Alex

I have seen this problem with Word in the past, and came up with this work-around using AppleScript to execute a shell-script on the Mac:

function open_a_file(tmpfile, application_name) {
	if (utils.stringMiddle(application.getOSName(), 1, 7) == "Windows") {
		application.executeProgram('rundll32', ['url.dll,FileProtocolHandler', tmpfile])
	} else if (utils.stringMiddle(application.getOSName(), 1, 7) == "FreeBSD" || utils.stringMiddle(application.getOSName(), 1, 5) == "Linux") {
		application.executeProgram('mozilla', [tmpfile])
	} else if (utils.stringMiddle(application.getOSName(), 1, 6) == "Mac OS") {
		var script = '';
		if (!application_name) {
			//to try to fix Kathy's problem, change logic for opening files
			script = 'tell application "Finder"\n';
			script += '	set command to "open " & quoted form of "' + tmpfile + '"\n';
			script += 'do shell script command\n';
			script += 'end tell';
		} else {
			script = 'tell application "' + application_name + '"\n';
			script += '	open "' + tmpfile + '"\n';
			script += 'end tell';
		}
		application.executeProgram('osascript', ['-e', script]);
	}
	return tmpfile;
}

Working here on

Servoy Client
Version 8.2.2 -build 3107
Java version 1.8.0_151 (Mac OS X)
OS: High Sierra (10.13.2)

Hi Christian,

thank you very much for your code!

Today i’ve tried your workaround and opened the file with Apple Script.
I’ve used the code without application_name, but unfortunately the file do not open with Preview, when the Preview app isn’t started yet.

Some Macs don’t have this issue. So i wonder what’s the difference.

Nobody else with this issue?

Thanks!
Alex

It seems there is an easy solution to fix this issue:

I’ve cleaned the Java Cache on those Macs and the issue has gone. :shock: