MacOS – Can you override app sandboxing, force app to use working directory

macospreviewsandbox

I'm trying to configure asymptote on my mac, which is a mathematical graphing language for LaTeX. The program is a Unix command line utility. According to the configuring instructions at http://asymptote.sourceforge.net/doc/Configuring.html, you can set the PDF reader for automatic opening with this utility. When I set pdfviewer="/Applications/Preview.app/Contents/MacOS/Preview"; (which is the path for the command line executable for Preview.app), then rending a graphic with asymptote results in this error:

2012-10-10 10:15:08.758 Preview[45884:707] PVPDFPageContainer initWithURL:out.pdf -- file://localhost/Users/username/Library/Containers/com.apple.Preview/Data/ failed, error = Error Domain=NSCocoaErrorDomain Code=260 "The file “out.pdf” couldn’t be opened because there is no such file." UserInfo=0x7f99f2c6d590 {NSFilePath=/Users/username/Library/Containers/com.apple.Preview/Data/out.pdf, NSUnderlyingError=0x7f99f2c6d500 "The operation couldn’t be completed. No such file or directory"}

Clearly Preview is attempting to open the document by filename in its local sandbox directory ~/Library/Containers/com.apple.Preview/Data/. Can I somehow override this behavior, and force Preview to look for the file in the process's working directory?

Best Answer

Create a shell script - ie asympdf.sh with the following content:

/Applications/Preview.app/Contents/MacOS/Preview `readlink -f $1`

If you put that script somewhere, ie near to the asymptote binaries, you can then set the pdfviewer setting to point to that script instead.