gnome/kde mime system - X

This is a discussion on gnome/kde mime system - X ; I am trying to figure out how to invoke the default application for a file using a shell command for gnome and kde. For instance in windows you type: start filename And the appropriate application will be opened. In Mac: ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: gnome/kde mime system

  1. gnome/kde mime system

    I am trying to figure out how to invoke the default application for a
    file using a shell command for gnome and kde. For instance in windows
    you type:
    start filename
    And the appropriate application will be opened. In Mac:
    open filename

    Anyone know how to do this?

    thanks


  2. Re: gnome/kde mime system

    epicwinter@hotmail.com wrote:
    > I am trying to figure out how to invoke the default application for a
    > file using a shell command for gnome and kde.


    Shell don't provide this. KDE and Gnome and even Gnome2 do have their own MIME
    tools, but those will only work for applications for that environment, so if
    you want some special application to be run when clicking on it's icon in
    konqueror/nautilus, then you have to set it for KDE and Gnome/Gnome2.

    > For instance in windows
    > you type:
    > start filename
    > And the appropriate application will be opened. In Mac:
    > open filename


    Sadly this is a quite bad way to associate files, as files can have the wrong
    "file extention", the proper way would be as it's done in Directory Opus (only
    for AmigaOS and Microsoft Windows), where you check the file for what type it
    is or/and on the file extention.


    > Anyone know how to do this?


    For KDE, take a look at the "KDE Components/File Associations".



    //Aho

  3. Re: gnome/kde mime system

    On Wed, 26 Jan 2005 21:10:25 +0100, J.O. Aho staggered into the Black
    Sun and said:
    > epicwinter@hotmail.com wrote:
    >> I am trying to figure out how to invoke the default application for a
    >> file using a shell command for gnome and kde.

    > Shell don't provide this.


    I think what epicwinter meant was "I'd like to launch whatever KDE or
    GNOME thinks is best for a file using a command-line app." This can be
    done; read on....

    > KDE and Gnome and even Gnome2 do have their own MIME tools, but those
    > will only work for applications for that environment, so if
    >> For instance in windows
    >> start filename
    >> And the appropriate application will be opened.

    > Sadly this is a quite bad way to associate files


    Bad or no, it's the lowest common denominator, so living with it and/or
    working around it is the easiest thing to do.

    > the wrong "file extention", the proper way would be as it's done in
    > Directory Opus (only for AmigaOS and Microsoft Windows), where you
    > check the file for what type it is or/and on the file extention.


    Konqueror does the equivalent of "file $FILE" on files that don't have a
    file extension that matches anything in its database.

    >> Anyone know how to do this?

    > For KDE, take a look at the "KDE Components/File Associations".


    This won't help epicwinter.

    AFAICT, you need to use DCOP to do this. Kind of like so:

    dcop konqueror-2882 KonquerorIface createNewWindow file:~/README.kwin

    ....Fine the name of your current konqueror session with "dcop | grep
    konqueror", assign that to $KONQ. Get the path of the file you want to
    open, prepend "file:" to it. Call that $URL. Then, it's just

    dcop $KONQ KonquerorIface createNewWindow $URL

    ....and presto. There are some DCOP tutorials out there if you Google
    for "DCOP tutorial". HTH,

    --
    Matt G|There is no Darkness in Eternity/But only Light too dim for us to see
    Brainbench MVP for Linux Admin / mail: TRAP + SPAN don't belong
    http://www.brainbench.com / Hire me!
    -----------------------------/ http://crow202.dyndns.org/~mhgraham/resume

  4. Re: gnome/kde mime system

    Dances with the Crows interpreted my need there exactly. I will try
    messing around with dcop. I wish konqueror could just automatically
    know the session that is open. But this is might be the hot ticket.

    I was hoping to do this in a single command line,based on the
    windows/mac usages. I was going to use a property like
    invokeApp=start $FILENAME //windows
    invokeApp=open $FILENAME //mac
    invokeApp=konqueror $FILENAME //linux OOPS a new konq window opens
    everytime

    Another option I was looking at was using mozilla since it can be used
    on every os:
    invokeApp=mozilla $FILENAME
    However, i run into the same problem with the multiple mozilla windows
    opening rather than just the application handler.


  5. Re: gnome/kde mime system

    epicwinter@hotmail.com wrote:

    > However, i run into the same problem with the multiple mozilla windows
    > opening rather than just the application handler.


    If you had run 'mozilla -help' you had found the option '-remote', which is to
    call an already running mozilla and there is an exelent web page they do
    direct too in that help too.

    To open a new url in a current mozilla window:
    mozilla -remote "openurl(http://www.linux.org)"


    //Aho

  6. Re: gnome/kde mime system

    JO Aho- this works well.
    mozilla -remote "openfile(file:/filename)"

    The only problem is if mozilla is not opened already, I get an error.
    You would think it would automatically start mozilla if it wasn't open.


  7. Re: gnome/kde mime system

    epicwinter@hotmail.com wrote:
    > JO Aho- this works well.
    > mozilla -remote "openfile(file:/filename)"
    >
    > The only problem is if mozilla is not opened already, I get an error.
    > You would think it would automatically start mozilla if it wasn't open.
    >


    There is the wonderfull world of shell scripts... here is a small one that
    should at least work in bash

    --- /usr/bin/openurl ---
    #!/bin/sh
    ISRUNNING=`ps -u $USER | grep -wc mozilla`
    if [ "$ISRUNNING" = "0" ]; then
    mozilla "$*" &
    else
    mozilla -remote "openurl($*)"
    fi
    --- eof ---

    after that

    chmod 755 /usr/bin/openurl


    Now you can use it

    openurl http://www.linux.org

    If no mozilla already loaded, it will load it in the background (this gives
    you the terminal back to you), if you have it already loaded, it will just
    open the url.



    //Aho

+ Reply to Thread