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?

  • If it's not possible to force a Mac app to open files in the working directory instead of its sandbox directory, then perhaps forcing asymptote to pass the full pathname instead of just the filename to Preview would work. How to do that is of course a question for the tex community, not the mac community.
    – ziggurism
    Oct 10, 2012 at 14:34
  • A generic solution there may be to have an intermediate shell script that creates the absolute filename based on the file relative the current working directory. "readlink <filename>" will give that output. Oct 10, 2012 at 15:27

1 Answer 1


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.

  • It's a good solution. Thank you. Can you tell me what the comman readlink does? I'm not familiar with it and the man page was hard to understand.
    – ziggurism
    Oct 14, 2012 at 19:57
  • 1
    Readline is originally intended for following symlinks and getting the original file, but it can also be used to get absolute pathnames out in bash too. The man page describes it as "canonicalize" - that is to find the one true file that all the symlinks (and the path may have more than one) point to. Oct 15, 2012 at 10:04
  • So actually I can't get this to work. readlink exits with "readlink: illegal option -- f". I'm on mountain lion 10.8, so maybe different versions of readlink accepted that option? Also using "stat -f" didn't work (the readlink man page suggested that alternative), actually it appears you have to include a format specifier with the -f switch, so I tried "stat -f "%N" filename", but that just outputs the filename, not the full pathname, so it still didn't work.
    – ziggurism
    Oct 16, 2012 at 16:22
  • I guess since the shell script inherits my current working directory, I don't have to mess with readlink or whatever. I can just specify the output filename, out.pdf. So in the end, my script is simply "open -a /Application/Preview.app out.pdf". Bash passes resolves the filename to the current working directory, and passes that to Preview, which is exactly what I want.
    – ziggurism
    Oct 16, 2012 at 18:16
  • Ah of course - I forgot that the gnu version is not what is provided on OSX (readlink works in linux, or if you've installed gnu versions) - this has an alternative - stackoverflow.com/questions/1055671/… - but as you say, you could just use the pwd. Oct 17, 2012 at 22:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .