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

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

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

Postby LXS » Mon Dec 18, 2017 7:09 pm

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:

Code: Select all
var tmpFile= plugins.file.createTempFile(...)
plugins.file.writeFile(tmpFile, blob)


Then i try to open that file:

Code: Select all
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:

Code: Select all
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
Alexander Stefan
Dr. Maison & Partner GmbH
www.servoy-plugins.de
www.maison-partner.de
LXS
 
Posts: 116
Joined: Thu Mar 01, 2007 12:00 am

Re: Mac Sandbox issue opening file with executeProgram('open

Postby swingman » Tue Dec 19, 2017 12:26 pm

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:

Code: Select all
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)
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1207
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Re: Mac Sandbox issue opening file with executeProgram('open

Postby LXS » Mon Jan 08, 2018 4:56 pm

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
Alexander Stefan
Dr. Maison & Partner GmbH
www.servoy-plugins.de
www.maison-partner.de
LXS
 
Posts: 116
Joined: Thu Mar 01, 2007 12:00 am

Re: Mac Sandbox issue opening file with executeProgram('open

Postby LXS » Wed Jan 10, 2018 11:46 am

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:
Alexander Stefan
Dr. Maison & Partner GmbH
www.servoy-plugins.de
www.maison-partner.de
LXS
 
Posts: 116
Joined: Thu Mar 01, 2007 12:00 am


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 5 guests

cron