Applescript to launch X11 GV or ghostview application

As I moved to Catalina, and 32 bit apps don't work anymore, I'm trying to recreate a droplet that could open a postscript file using the gv command. In the past I used the XDroplet app, which did the trick in a complicated way but this is 32 bit.

I now wrote a simple applescript:


run application "XQuartz"

on open filelist

repeat with filename in filelist

set mycmd to "/opt/local/bin/gv " & POSIX path of filename

do shell script mycmd

end repeat

end open

tell application "XQuartz" to activate


but while this does open XQuartz and the gv app, the app then gets stuck (small clock) and never opens the actual file which I dropped.

Instead I found that if I modify the script to launch the same from within a terminal, then everything works:


run application "XQuartz"

on open filelist

repeat with filename in filelist

set mycmd to "/opt/local/bin/gv " & POSIX path of filename

tell application "Terminal"

do script mycmd & "; exit"

end tell

end repeat

end open

tell application "XQuartz" to activate


Could anybody tell me why I cannot make it work without running within the Terminal?

Thanks

MacBook Pro 15", OS X 10.11

Posted on Nov 17, 2019 2:28 AM

Reply
Question marked as Top-ranking reply

Posted on Nov 18, 2019 1:34 PM

Maybe instead of running mycmd directly, try routing it through "zsh -c”. That might pick up the environment variables you are missing when running the command directly.

Similar questions

7 replies

Nov 17, 2019 7:54 AM in response to maurizioplll

When you run the Applescript what, is the DISPLAY environment variable


Inside your Applescript run the following command via "do shell script"

printenv DISPLAY >/tmp/what.is.display.txt


It should be something like:

/private/tmp/com.apple.launchd.RnABlsxhQB/org.macosforge.xquartz:0

where the RnABlsxhQB is going to be unique for you and different from what I'm seeing


But actually VikingOSX is a much better idea.

Nov 17, 2019 3:31 AM in response to maurizioplll

Apple's Preview application will convert PostScript, and encapsulated PostScript into PDF, and present it without changing the original source file, or having to install the three-year old, unsupported XQuartz. Thus, you could make a simple change to your mycmd, and skip ghostview and XQuartz altogether:


open -a Preview tiger.eps



The following was hand-coded right out of the Adobe PostScript Blue book:


open -a Preview circular.ps


Nov 17, 2019 1:45 PM in response to VikingOSX

Thanks, but this option is not my favorite. Apart the fact that I find Preview very unreliable lately (it keeps loosing annotations, highlighting in the text is often misplaced etc., but these are other issues), my need is to be able to open large, multi-page postscripts. Preview will convert all pages taking a while, while GV simply loads one at a time making the process more efficient. Also, GV automatically refreshes the viewer when the original file changes, while as far as I know there is no such feature in Preview where I have to re-convert the whole file again every time. However if you know a viewer or Preview option that works like GV, I would be happy to switch.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript to launch X11 GV or ghostview application

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.