Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  Joe Hannon Oct 10 '12 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. –  Danny Staple Oct 10 '12 at 15:27

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
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. –  Joe Hannon Oct 14 '12 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. –  Danny Staple Oct 15 '12 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. –  Joe Hannon Oct 16 '12 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. –  Joe Hannon Oct 16 '12 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. –  Danny Staple Oct 17 '12 at 22:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.