LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Editing .desktop files (https://www.linuxquestions.org/questions/linux-newbie-8/editing-desktop-files-4175668369/)

MPS$mps 01-24-2020 01:11 PM

Editing .desktop files
 
I'm running Debian Buster (10.2), and wish to cause my Firefox browser
desktop icon's label to AUTOMATICALLY include the version number of Firefox I am using.
The .desktop file currently is:
****************************************************************************
#!/usr/bin/env xdg-open

[Desktop Entry]
Name=Firefox
Comment=Browse the World Wide Web
GenericName=Web Browser
X-GNOME-FullName=Firefox Web Browser
Exec=/opt/firefox/firefox %u
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/opt/firefox/browser/chrome/icons/default/default48.png
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/vnd.mozilla.xul+xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;
StartupWMClass=Firefox
StartupNotify=true
Name[en_GB]=Firefox /bin/cat /opt/firefox/application.ini:8
****************************************************************************
Where I had expected the "/bin/cat /opt/firefox/application.ini:8" to yield the version number of "72.0.2", therefore giving the label under the Firefox icon as "Firefox 72.0.2".

But instead, the label reads "Firefox /bin/cat /opt/firefox/application.ini:8"

Is there anyone who knows how to get the version number of an application
to AUTOMATICALLY be a part of the application's Desktop icon's label?

Thanks in advance!

BW-userx 01-24-2020 09:09 PM

Code:

Name=Firefox 72.0.2
you could write a little script to sed your desktop file and update the version every time it is updated.

vtel57 01-24-2020 09:11 PM

Yeah, but the OP is trying to get something set up so that the name updates with the correct version each time the FF is updated. Just editing NAME won't do that. Good suggestion, though.

BW-userx 01-24-2020 09:43 PM

Quote:

Originally Posted by vtel57 (Post 6082698)
Yeah, but the OP is trying to get something set up so that the name updates with the correct version each time the FF is updated. Just editing NAME won't do that. Good suggestion, though.

because it is not a script and I do not think it can be seen as one either, so it cannot be include within the file itself, therefore, a simple one liner placed within a a script then placed within ones home bin with the path set in the .bashrc to that dir then off the cli just call the script name.
Code:

[[ -d $HOME/bin ]] && { PATH=$PATH:$HOME/bin ; }
Code:

$ sed  's/Name.*/Name='"$(firefox -v)"'/' /home/userx/Desktop/delteme.desktop
#!/usr/bin/env xdg-open
[Desktop Entry]
Name=Mozilla Firefox 72.0.2
Comment=Browse the World Wide Web
GenericName=Mozilla Firefox 72.0.2
X-GNOME-FullName=Mozilla Firefox 72.0.2
Exec=firefox %u
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=firefox
Categories=Network;WebBrowser;

as one can see this works. where the set Name in the file itself is Name=Firefox 72.0.2

yes, sometimes we have to make adjustments to how we do things to get the desired effects in what it is one wants to do. so a manual running of a simple script is all that would be needed in this case, and even could be set up to be automated if one want to take on that endeavor.

ondoho 01-25-2020 09:43 AM

Quote:

Originally Posted by MPS$mps (Post 6082551)
I'm running Debian Buster (10.2), and wish to cause my Firefox browser
desktop icon's label to AUTOMATICALLY include the version number of Firefox I am using.
The .desktop file currently is:
****************************************************************************
#!/usr/bin/env xdg-open

[Desktop Entry]
Name=Firefox
Comment=Browse the World Wide Web
GenericName=Web Browser
X-GNOME-FullName=Firefox Web Browser
Exec=/opt/firefox/firefox %u
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/opt/firefox/browser/chrome/icons/default/default48.png
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/vnd.mozilla.xul+xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;
StartupWMClass=Firefox
StartupNotify=true
Name[en_GB]=Firefox /bin/cat /opt/firefox/application.ini:8
****************************************************************************
Where I had expected the "/bin/cat /opt/firefox/application.ini:8" to yield the version number of "72.0.2", therefore giving the label under the Firefox icon as "Firefox 72.0.2".

But instead, the label reads "Firefox /bin/cat /opt/firefox/application.ini:8"

Is there anyone who knows how to get the version number of an application
to AUTOMATICALLY be a part of the application's Desktop icon's label?

Thanks in advance!

Are you saying the file actually contains the string "#!/usr/bin/env xdg-open"??? Strange, never seen that.

Please use CODE tags for code and output from now on.

First things first: you can get the version with 'firefox -v'

You want it automated - triggered how? On upgrade? How did you install? How do you upgrade FF?

pan64 01-25-2020 10:08 AM

(If I understand well) that is a static entry in the desktop file. If you wish to update it you need to write a script to look for the version info and put it into this file.

Geist 01-25-2020 10:56 AM

How about a potentially galaxy brained solution:
Writing a pseudo device (like /dev/null ) that generates the content of the desktop file when read (and of course symlinked to where it would be).

Probably overkill, but...gotta get that *nix knowledge somehow, or something, right?

Note: I actually don't really know what I'm talking about here, but if this is feasible, then why not do it for fun?

ondoho 01-26-2020 02:47 AM

If FF is installed via package management then it's not so difficult to trigger a sed to the .desktop file after every upgrade.

MPS$mps 01-31-2020 03:18 PM

Editing .desktop files
 
To BW-userx: vtel57's reply nailed my intention, but using your method (if I understand it- your description is not entirely clear) is only slightly easier than manually editing the firefox.desktop file. Anyway, amen to your rules 1-5!

To ondoho: Yes, the firefox.desktop file REALLY does lead off with the string "#!/usr/bin/env xdg-open". Maybe it's just a Debian thing? IDK. And I want the new version number triggered on upgrade. BTW, am I using the code tag properly here?:

Code:

#!/usr/bin/env xdg-open

[Desktop Entry]
Name=Firefox
Comment=Browse the World Wide Web
GenericName=Web Browser
X-GNOME-FullName=Firefox Web Browser
Exec=/opt/firefox/firefox %u
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/opt/firefox/browser/chrome/icons/default/default48.png
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/vnd.mozilla.xul+xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;
StartupWMClass=Firefox
StartupNotify=true
Name[en_GB]=Firefox /bin/cat /opt/firefox/application.ini:8

And lastly, it would appear that the proper use of sed is what I need, but right now, my sed-fu is zero. See my response to Geist, below.

To pan64: I can be dense, but not THAT dense!

To Geist: Yeah. It's like, everything's a RESEARCH PROJECT!

NOW: Can someone instruct me on how to respond to future repliers INDIVIDUALLY? I've searched LQ's faq and tutorial to no avail (or perhaps it's Noah Wylie).

BW-userx 01-31-2020 04:31 PM

it is a simple sed command find and replace. Using bash varitable handling.
Code:

sed  's/Name.*/Name='"$(firefox -v)"'/' /home/userx/Desktop/delteme.desktop
break it down now...

basic set up
Code:

sed /find/replace/
find the word 'NAME' in file
Code:

sed 's/Name.*" <-- gets name and anything after that using .*
replace. get the version of current installed firefox (in PATH).
Code:

$ echo $(firefox -v)
Mozilla Firefox 68.1.0esr

what sed does automatically is get the value within the $( ) of
hence issuing that command and file to sed will change every instance of NAME with the output of 'firefox -v'
so
NAME=Firefox now equals NAME=Mozilla Firefox 68.1.0esr

more constraints can be put on it, and editing the "Mozilla Firefox 68.1.0esr" to make it maybe 'Firefox 68.1.0esr' too can be done in a script or command line. by cutting the output first then using the results for sed command. but that is a earning curve.

before
Code:

$ cat mozilla-firefox.desktop
[Desktop Entry]
Exec=firefox %u
Icon=firefox
Type=Application
Categories=Network;WebBrowser;
Name=Firefox
MimeType=text/html;text/xml;application/xhtml+xml;application/vnd.mozilla.xul+xml;text/mml;x-scheme-handler/http;x-scheme-handler/https;
X-KDE-StartupNotify=true

after
Code:

$ sed 's/Name.*/Name='"$(firefox -v)"'/' mozilla-firefox.desktop
[Desktop Entry]
Exec=firefox %u
Icon=firefox
Type=Application
Categories=Network;WebBrowser;
Name=Mozilla Firefox 68.1.0esr
MimeType=text/html;text/xml;application/xhtml+xml;application/vnd.mozilla.xul+xml;text/mml;x-scheme-handler/http;x-scheme-handler/https;
X-KDE-StartupNotify=true

list stated before in here, you can add that to a after update hook to run it then automatically.

vtel57 01-31-2020 09:26 PM

> NOW: Can someone instruct me on how to respond to future repliers INDIVIDUALLY?

You can manually multi-quote everyone you care to reply to in a single posting by manually coding the quotes with UBBCode:

[quote ]poster's text[/quote ] --> no space before the closing brackets*

You can also add the poster's username to the quote like this:

[quote=vtel57 ]vtel57's text[/quote ] --> again remove space before closing brackets*

*I added the space so that the board's software would not parse the code, so you could see it.

Quote:

Poster 1's text here.
Then add your reply.

Quote:

Poster 2's text here.
Your reply.

Quote:

Poster 3's text here.
And so on.

Or you can quote and reply to each poster in a separate reply; not too efficient, though.

If I've totally missed what you're trying to ask above, just holler louder. I'm old. ;)

And if anyone else here knows a better way to multi-quote, please chime in.

Later...

~Eric

ondoho 02-03-2020 01:19 AM

Now you learned how to use sed, the next step would be this:
https://www.cyberciti.biz/faq/debian...grade-command/


All times are GMT -5. The time now is 10:36 AM.