file associations at the CLI level?
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. 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. Thanks Greg -- Greg Freemyer The Norcross Group Forensics for the 21st Century
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. -- kai ponte www.perfectreign.com
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
On Thursday 09 November 2006 12:40, Randall R Schulz wrote:
On Thursday 09 November 2006 13:28, Kai Ponte wrote:
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
I submit that kfmclient exec <filename> is sufficient for most purposes. Try it. -- _____________________________________ John Andersen
I submit that kfmclient exec <filename> is sufficient for most purposes. Try it.
-- _____________________________________ John Andersen
Thanks John, I'll have to get back to the user/programmer and see if that will do the job but it works for me. Greg -- Greg Freemyer The Norcross Group Forensics for the 21st Century
On Thursday 09 November 2006 11:25, Greg Freemyer wrote:
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.
And hence their problem with viruses, remote exploits etc. You don't want this. -- _____________________________________ John Andersen
On 11/9/06, Greg Freemyer
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.
In the future, distributions will include a command called xdg-open that does this. It is part of the Portland initiative. For now, you can download it here http://portland.freedesktop.org/wiki/ Claes -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The Thursday 2006-11-09 at 15:25 -0500, Greg Freemyer wrote:
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.
Yes, but this is dangerous. I don't wan't it. - -- Cheers, Carlos E. R. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Made with pgp4pine 1.76 iD8DBQFFb2+LtTMYHG2NR9URAjH8AJoDen7MOgVHlQ+F4PONRvmLyXsZewCfQ8Qy vkMPZJvMcZFcFaPh+Lfn1GQ= =JXka -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (6)
-
Carlos E. R.
-
Claes@work
-
Greg Freemyer
-
John Andersen
-
Kai Ponte
-
Randall R Schulz