file associations at the CLI level?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

file associations at the CLI level?

gregfreemyer
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

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: file associations at the CLI level?

PerfectReign
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

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: file associations at the CLI level?

Randall Schulz
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

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]

open (408 bytes) Download Attachment
furl (541 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: file associations at the CLI level?

John Andersen
In reply to this post by gregfreemyer
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

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: file associations at the CLI level?

John Andersen
In reply to this post by 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

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: file associations at the CLI level?

gregfreemyer
>
> 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

--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: file associations at the CLI level?

Tom Peters
In reply to this post by gregfreemyer
At 03:25 PM 11/9/2006 -0500, you 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.

Typically you have to use the CMD shell built-in "start" but I noticed that
in XP the shell consults the file "associations" in the registry and starts
the associated "open" action. Note that for this to work you have to
specify the file and type. typing zapotec will not work, if zapotec is a
bitmap image, but typing zapotec.bmp will. Other examples:

start localtext.html
start somefile.txt
even this works:

start .

That last one opens an explorer window at the cwd.

START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
       [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
       [/WAIT] [/B] [command/program]
       [parameters]

     "title"     Title to display in  window title bar.
     path        Starting directory
     B           Start application without creating a new window. The
                 application has ^C handling ignored. Unless the application
                 enables ^C processing, ^Break is the only way to interrupt
                 the application
     I           The new environment will be the original environment passed
                 to the cmd.exe and not the current environment.
     MIN         Start window minimized
     MAX         Start window maximized
     SEPARATE    Start 16-bit Windows program in separate memory space
     SHARED      Start 16-bit Windows program in shared memory space
     LOW         Start application in the IDLE priority class
     NORMAL      Start application in the NORMAL priority class
     HIGH        Start application in the HIGH priority class
     REALTIME    Start application in the REALTIME priority class
     ABOVENORMAL Start application in the ABOVENORMAL priority class
     BELOWNORMAL Start application in the BELOWNORMAL priority class
     WAIT        Start application and wait for it to terminate
     command/program
                 If it is an internal cmd command or a batch file then
                 the command processor is run with the /K switch to cmd.exe.
                 This means that the window will remain after the command
                 has been run.

                 If it is not an internal cmd command or batch file then
                 it is a program and will run as either a windowed application
                 or a console application.

     parameters  These are the parameters passed to the command/program





[Philosophy] Experience is something you don't get until just after
you need it. --Olivier
--... ...--  -.. .  -. ----. --.- --.- -...
[hidden email]   (remove "nospam") N9QQB (amateur radio)
"HEY YOU" (loud shouting)  WEB ADDRESS http//www.mixweb.com/tpeters
43° 7' 17.2" N by 88° 6' 28.9" W,  Elevation 815',  Grid Square EN53wc
WAN/LAN/Telcom Analyst, Tech Writer, MCP, CCNA, Registered Linux User 385531




--
Check the headers for your unsubscription address
For additional commands send e-mail to [hidden email]
Also check the archives at http://lists.suse.com
Please read the FAQs: [hidden email]