You are not logged in.

#1 2013-01-17 13:25:12

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Tool to open a desktop file

I am looking for a tool that open a .desktop file. 

For example, we can get the default browser with

$ xdg-mime query default x-scheme-handler/http
$ chromium.desktop

But now I would like to open chromium.desktop. I have found on the web scripts that parse the .desktop file but nothing complete. We should properly look for the .desktop file in the appropriate directories and parse it fully (understanding comment, and various parameters %U, %s with proper quotation). Everything that is mentioned here: http://standards.freedesktop.org/deskto … atest.html. Does such tool exist?

Last edited by olive (2013-01-17 13:27:05)

Offline

#2 2013-01-17 13:28:21

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,554
Website

Re: Tool to open a desktop file

This sounds like an X-Y problem.  Why use xdg-mime to get the desktop file of the application that should open the file, then try to run the application?  Just use xdg-open in the first place.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2013-01-17 14:04:05

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Tool to open a desktop file

Trilby wrote:

This sounds like an X-Y problem.  Why use xdg-mime to get the desktop file of the application that should open the file, then try to run the application?  Just use xdg-open in the first place.

xdg-open only works if you have actually something to open. The problem I have have is that I would like to open the default browser without URLs. xdg-open does not seem to be able to do that. I guess it would be possible to patch xdg-open, but I do not know perl.

Offline

#4 2013-01-17 14:21:43

DSpider
Member
From: Romania
Registered: 2009-08-23
Posts: 2,273

Re: Tool to open a desktop file

They look like text files to me. Open them in nano, in Leafpad or whatever.


"How to Succeed with Linux"

I have made a personal commitment not to reply in topics that start with a lowercase letter. Proper grammar and punctuation is a sign of respect, and if you do not show any, you will NOT receive any help (at least not from me).

Offline

#5 2013-01-17 14:35:54

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Tool to open a desktop file

DSpider wrote:

They look like text files to me. Open them in nano, in Leafpad or whatever.

I would like to have a script that open the default browser. What is needed is to parse the script. But I would like to do it well, understanding all possibilities.

Offline

#6 2013-01-17 14:36:15

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Tool to open a desktop file

I'm not sure I understand what's going on, but DSpider is correct that .desktop files are just text. Do you just want a desktop launcher for chromium (like a windows shortcut) or something to go on a panel, or hmm ?

You might also look into Freedesktop menu spec. That's what I used just last weekend to make some custom launchers and get them into my Xfce Applications Menu.

Also, keep in mind you can (and should) use the $XDG_DATA_HOME directory for your customized .desktops, .directories, and .menus.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#7 2013-01-17 14:43:09

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Tool to open a desktop file

alphaniner wrote:

I'm not sure I understand what's going on, but DSpider is correct that .desktop files are just text. Do you just want a desktop launcher for chromium (like a windows shortcut) or something to go on a panel, or hmm ?

You might also look into Freedesktop menu spec. That's what I used just last weekend to make some custom launchers and get them into my Xfce Applications Menu.

Also, keep in mind you can (and should) use the $XDG_DATA_HOME directory for your customized .desktops, .directories, and .menus.

What I would like is a script "default-browser" that open the default browser (chromium in this example, but whatever is registered as the default browser). I can then use this script in various program that do not understand freedesktop; for example barebone windows manager like icewm. I can read all the specs and write a script but there is a lot of details. I just wonder if such scripts already exist. More generally, it would be great if we have a full command line .desktop parser that understand everything; that's way I ask the question.

Last edited by olive (2013-01-17 14:45:53)

Offline

#8 2013-01-17 14:47:50

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,554
Website

Re: Tool to open a desktop file

#!/bin/bash

execline=$(grep "^Exec=" $1)
prog=${execline/Exec=/}
exec ${prog/ */}

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#9 2013-01-17 15:14:31

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Tool to open a desktop file

I'd go with something like execline=$( grep -m1 "^Exec=" /usr/share/applications/$(xdg-mime query default x-scheme-handler/http) )

That said, xdg-mime query default x-scheme-handler/http returns "userapp-Firefox-700S4V.desktop" for me, and that file is located at ~/.local/share/applications/. So you might need have something in the script to locate the file, rather than assume it's located in /usr/share/applications.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#10 2013-01-17 16:16:25

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Tool to open a desktop file

The solutions proposed work most of the time, but it is easy to make a valid desktop file that do not work; for example:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
NoDisplay=true
Exec= /usr/lib/firefox/firefox -P myprofile %u
Name=Firefox
Comment=Custom definition for Firefox

(Note the space after exec and the option -P. There are tons of details like that. Including strange characters that must be escaped; for example if you would like to open a program literally named "%I" (with the quote making part of the filename) (I think this should be written \"%%I\" in the .desktop file, but I'm not sure). I wonder if the freedesktop fog (or someone other) has made such a program. If big desktop like Gnome or KDE would like to be 100% freedesktop compliant, the code must already exist somewhere; but maybe not in a standalone script.

Last edited by olive (2013-01-17 16:20:13)

Offline

#11 2013-01-17 17:10:30

aesiris
Member
Registered: 2012-02-25
Posts: 97

Re: Tool to open a desktop file

olive wrote:

[...]the code must already exist somewhere; but maybe not in a standalone script.

xdg-open is actually just an sh script, maybe you will find your answer inside it

less `which xdg-open`

for example it extracts the command line with:

grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2-

Offline

#12 2013-01-17 17:55:56

jjacky
Member
Registered: 2011-11-09
Posts: 347
Website

Re: Tool to open a desktop file

You can probably use an application autostarter to do so, since what they do is read .desktop files and "start them" based on those freedesktop specs.

For example, I use this, and while you can't give it a .desktop file, it can take a folder a parameter, reading & "starting" all .desktop files in there. (There might even be some autostarters that take .desktop file as parameter...)

Offline

#13 2013-01-17 19:50:23

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Tool to open a desktop file

jjacky wrote:

You can probably use an application autostarter to do so, since what they do is read .desktop files and "start them" based on those freedesktop specs.

For example, I use this, and while you can't give it a .desktop file, it can take a folder a parameter, reading & "starting" all .desktop files in there. (There might even be some autostarters that take .desktop file as parameter...)

This is indeed nearly what I want. When I have more time, I will see if I can hack the source in order that they start a single .desktop file. In principle, it should not be difficult.

Offline

#14 2013-01-17 20:22:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,554
Website

Re: Tool to open a desktop file

Ah ... if that's what you want, nearly every panel application (eg tint2) has that built in.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB