On Thursday 09 November 2006 13:28, Kai Ponte wrote:
On Thursday 09 November 2006 12:25, Greg Freemyer wrote:
All,
I've just had a Windows users/programmer ask me a question that's new to me.
Apparently in Windows if you have a command prompt the file extension associations work.
Thus if you have a .html file in the current directory, you can just type the name of the file and hit return. The command interpreter figures out there is an application associated with and launches the associated file. In this case an Internet Browser gets launched.
Hmm...never tried that. Yes, it works. I also tried it with .doc (Word), .txt (EditPad), and .xls (Excel) files. Interesting.
In linux I know files can start with #!/bin/sh etc. and cause various interpreters to be launched. Is there a way to cause an html file to auto launch a browser. And if so is there a way to do it if you don't know the full path of the browser. ie. we just want to say, shell launch default Internet Browser.
You apparently cannot simply type file.html and have it launch Firefox or Konqueror or Nautilus. However, you can type - for example - firefox file.html and it will launch.
I cobbled together a simple hack that works for most files. It requires KDE, but presumably there's an equivalent that will work under Gnome and probably other desktop environments. I call it "open" and I use it very frequently: -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==- #!/bin/bash --norc for doc; do if [[ "$doc" = file://* ]]; then kfmclient exec "$doc" >>"$HOME/.xsession-errors" 2>&1 else if [ ! -f "$doc" ]; then echo "open: Document file \"$doc\" does not exist" 2>&1 elif [ ! -r "$doc" ]; then echo "open: Document file \"$doc\" is not readable" 2>&1 else kfmclient exec "$(furl "$doc")" >>"$HOME/.xsession-errors" 2>&1 fi fi done -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==- It uses another command called "furl" (for File URL) to produce the URLs it passes to kfmclient: -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==- #!/bin/bash --norc for arg; do case "$arg" in /*) echo "file://$arg" ;; .) echo "file://$(pwd)" ;; ./*) echo "file://$(pwd)/${arg#./}" ;; ../*) echo "file://$(cd ..; pwd)/${arg#../}" ;; ..) echo "file://$(cd ..; pwd)" ;; *) echo "file://$(pwd)/$arg" ;; esac done exit #!/bin/bash --norc # Generate "file:" URL for each argument for arg; do case "$arg" in /*) echo "file://$arg" ;; *) echo "file://$PWD/$arg" ;; esac done -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==- I've attached two these as text files. If the list server allows them, they'll be there untouched by various mail mollestations. When I started using MacOS X I was pleased to learn there was already a built-in command there called "open" which did the same thing, except it brought to bear the full power of the Macintosh Desktop / Finder to determine what to do, and thus is less often fooled.
-- kai ponte www.perfectreign.com
Randall Schulz