 |
 |
Associating X11 apps with filetypes?
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Sep 2002
Location: Toronto
Status:
Offline
|
|
Is there a clever way (i.e. a script which runs a Unix command) that I can associate an X11 app with a filetype? I would love to be able to double-click/download a .ps file and have it automatically open under gv, given the lack of decent postscript previewers for the mac. (Bonus points if I can get also get .ps files to show up in the finder with a nice icon!)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status:
Offline
|
|
Yes. In fact over at OSHints I gave an example of doing it.
http://www.macosxhints.com/article.p...27218#comments
In the hint I provided a way to open .ps (postscript files) and then pass them to Ghostscript (installed with Fink) and then open the files with Adobe Acrobat.
The basic gist of the hint is to create an Applescript that takes what is passed to it and sends it to a shell script.
Code:
on open input_file
do shell script "export PATH="$PATH":/sw/bin;ps2pdf"
& POSIX path of input_file & " /tmp/.psview.tmp.pdf"
do shell script "open /tmp/.psview.tmp.pdf"
end open
So to do what you want, say associate files with AbiWord, you'd create the following script
Code:
on open input_file
do shell script "/sw/AbiWord " & POSIX path of input_file & do
end open
I've not tested that last one, but the former one I use quite a bit since there is no good Distiller for OSX. (Although that will change when Acrobat 6.0 comes out -- hopefully this fall)
This, by the way, is a great way to utilize utilities from Linux available on SourceForge.org to the Mac. For instance I made a drag and drop app like the above to deal with rar files.
(Last edited by clarkgoble; Jan 10, 2003 at 08:49 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Sep 2002
Location: Toronto
Status:
Offline
|
|
Excellent! Many thanks. One glitch still - running the script
on open filelist
repeat with i in filelist
do shell script "/sw/bin/gv " & quoted form of POSIX path of i
end repeat
end open
I get the dreaded "Error: cannot open display". I tried replacing it with
do shell script "DISPLAY=:0.0; /sw/bin/gv " & quoted form of POSIX path of i
but still no luck. What am I missing?
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Apr 2001
Location: NY, NY, USA
Status:
Offline
|
|
|
|
|
- Sahara
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status:
Offline
|
|
Yeah, you're right. Unlike XDarwin, calling shell script in Applescript doesn't seem to know about X11. If you use Apple's "open-x11" shell script that will solve the problem.
You can actually get the same effect as using open-x11 by exporting the Display.
do shell script "export DISPLAY=\":0.0\"; /sw/bin/gnumeric&"
If you think there will be output in either stdout or stderr you can redirect those.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Sep 2002
Location: Toronto
Status:
Offline
|
|
Thanks sahara and clarkgoble for your help - one more thing ... with the script
on open fileList
tell application "X11" to activate
repeat with i in fileList
do shell script "PATH=$PATH:/sw/bin:/bin:/usr/bin:/usr/local/bin; export DISPLAY=\":0.0\"; gv " & quoted form of POSIX path of i
end repeat
end open
(I need to add /sw/bin to the path because gv calls gs, which it otherwise can't find) if I drop two files on the icon it displays the first, but won't open the second until I close it. So presumably I need something to tell it not to wait around for the first gv to finish before moving on to the second. What do I have to add to get it to open them all at the same time?
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Apr 2001
Location: NY, NY, USA
Status:
Offline
|
|
Did you try it with the " > /dev/null 2>&1 &"?
|
|
- Sahara
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Sep 2002
Location: Toronto
Status:
Offline
|
|
ah, so that's what that does ...
Works now. Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status:
Offline
|
|
If you want to run a shell program but continue using the shell you put the & character after the command.
So if you type xterm in an xterm window, you'll notice you can't use the first xterm until you quit the second one. However if you add an & and type "xterm&" you'll be able to use both.
The other part is a bit more complex. In Unix you can save the output of a command to a file using the > symbol. Thus if you typed "ls > mydir.txt" you'd get the directory listing provided by ls saved in the file mydir.txt. What /dev/null does is act like an infinite black hole file. You can output commands there and they simply are discared. You'll see it used a lot in shell programs when people just want to ignore output. While some X11 apps are good about not writing to the terminal, others write a lot of information. (The KDE apps are particularly noteworthy here)
In Unix there are actually two output streams. One, mentioned above, is the typical output of a program and is called stdout. The other is for errors and is stderr. Often you'll save stdout to a file but have stderr display on the screen. What Sahara did was redirect [i]both[/b] to /dev/null. The reason it looks so convoluted is because of the way the csh works. It is actually much more straightforward if you use Bash or sh. Most people consider this a serious shortcoming with csh based shells, like tcsh.
So to send both stdout and stderr to /dev/null you type "mycmd > /dev/null 2>&1" and then add the & if you want it to run in the background.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|