same format all *.desktop files (organize info)

Here is a place for your projects which are not officially supported by the Porteus Team. For example: your own kernel patched with extra features; desktops not included in the standard ISO like Gnome; base modules that are different than the standard ISO, etc...
Post Reply
User avatar
bigbass
Contributor
Contributor
Posts: 151
Joined: 13 Jan 2012, 14:35
Distribution: slackware 14

same format all *.desktop files (organize info)

Post#1 by bigbass » 24 Mar 2012, 06:01

there is no official standard for desktops so it's time to start one that's clean and easy to read
I know its a pain to fix all the packages that's why this is a workaround without effecting the installed files

if you want to "grep out info " having it organized in arrarys first allows you find the info with
less code filters most of the problem with writing scripts is because "we start with un formatted files "

make a template of all the desktops and lets you view them in /tmp/desktops
so none of your original desktops get overwritten

builds an array for speeding up any scripts that search info from the desktop

now all your desktops will have a format and an organized template
the first line is [Desktop Entry],Name,Icon,Type,Categories,Exec,Comment,MimeType

and thats what you will expect to see when you search the desktops for info they will all follow this format
[Desktop Entry]
Name=Image Viewer
Icon=gpicview
Type=Application
Categories=Graphics;Utility;Core;GTK;Viewer;RasterGraphics;2DGraphics;Photography;
Exec=gpicview %f
Comment=View your images easily
MimeType=image/bmp;image/gif;image/jpeg;image/jpg;image/png;image/tiff;image/x-bmp;image/x-pcx;image/x-tga;image/x-portable-pixmap;image/x-portable-bitmap;image/x-targa;image/x-portable-greymap;application/pcx;image/svg xml;image/svg-xml;





Code: Select all

#!/bin/bash


    # make a template  of the desktops regenerate all desktops  to the new simple template
    # removes poorly formatted desktops and creates a standard  which allows later  for easy reading of strings
    # into an array to speed up scripts since the newly generated desktops maintain a standard format
    # less commands are needed to filter data for output this is where all the time is wasted
    # having to parse poorly formatted files from the start if you have organized files
    # everything is fast and easy to  parse the code

    :>/tmp/arraytest.txt
    mkdir -p /tmp/desktops

    for DESKTOP_FILE in /usr/share/applications/* ; do
        while read LINE ; do
          case $LINE in
             Name=*) NAME="${LINE[@]}"'|'   ;;
             Icon=*) ICON="${LINE[@]}"'|'   ;;
             #Terminal=*)
             Type=*) TYPE="${LINE[@]}"'|'   ;;
             Categories=*) CATS="${LINE[@]}"'|'   ;;
             Exec=*) EXEC="${LINE[@]}"'|'   ;;
             Comment=*) COMM="${LINE[@]}"'|'   ;;
             MimeType=*) MIMETYPE="${LINE[@]}"'|'   ;;
          esac     
       done < $DESKTOP_FILE
       echo "."
     
       # fixes spaces in the string names by replacing them with a "+" making a correctly formatted array
          echo '[Desktop+Entry]|'$NAME$ICON$TYPE$CATS$EXEC$COMM$MIMETYPE | tr ' ' '+'  >>/tmp/arraytest.txt
        #uncomment if you want to generate all new desktops in /temp/desktops
        echo '[Desktop+Entry]|'$NAME$ICON$TYPE$CATS$EXEC$COMM$MIMETYPE | tr ' ' '+' | tr '| ' ' ' | tr ' ' '\n' | tr '+' ' '>/tmp/desktops/`basename $DESKTOP_FILE`
    done

if you want to fix KDE desktops too here it is

Code: Select all

#!/bin/bash

    # kde version
    # make a template  of the desktops regenerate all desktops  to the new simple template
    # removes poorly formatted desktops and creates a standard  which allows later  for easy reading of strings
    # into an array to speed up scripts since the newly generated desktops maintain a standard format
    # less commands are needed to filter data for output this is where all the time is wasted
    # having to parse poorly formatted files from the start if you have organized files
    # everything is fast and easy to  parse the code

    :>/tmp/arraytest.txt
    mkdir -p /tmp/desktops/kde-folder

    for DESKTOP_FILE in /usr/share/applications/kde/* ; do
        while read LINE ; do
          case $LINE in
             Name=*) NAME="${LINE[@]}"'|'   ;;
             Icon=*) ICON="${LINE[@]}"'|'   ;;
             #Terminal=*)
             Type=*) TYPE="${LINE[@]}"'|'   ;;
             Categories=*) CATS="${LINE[@]}"'|'   ;;
             Exec=*) EXEC="${LINE[@]}"'|'   ;;
             Comment=*) COMM="${LINE[@]}"'|'   ;;
            MimeType=*) MIMETYPE="${LINE[@]}"'|'   ;;
          esac     
       done < $DESKTOP_FILE
       echo "."
     
       # fixes spaces in the string names by replacing them with a "+" making a correctly formatted array
          echo '[Desktop+Entry]|'$NAME$ICON$TYPE$CATS$EXEC$COMM$MIMETYPE | tr ' ' '+'  >>/tmp/arraytest.txt
        #uncomment if you want to generate all new desktops in /temp/desktops
        echo '[Desktop+Entry]|'$NAME$ICON$TYPE$CATS$EXEC$COMM$MIMETYPE | tr ' ' '+' | tr '| ' ' ' | tr ' ' '\n' | tr '+' ' '>/tmp/desktops/kde-folder/`basename $DESKTOP_FILE`
    done





User avatar
brokenman
Site Admin
Site Admin
Posts: 5439
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v3.2rcX all desktops
Location: Brazil
Contact:

Re: same format all *.desktop files (organize info)

Post#2 by brokenman » 25 Mar 2012, 13:10

I'm not sure i understand how this makes parsing .desktop files more efficient. I thought the standard for desktop files was set by these guys:
http://standards.freedesktop.org/deskt ... atest.html

Would be good if we had a way to measure efficiency. For now i will run your script against desktop files and check it out. Thanks for another great contribution.
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
bigbass
Contributor
Contributor
Posts: 151
Joined: 13 Jan 2012, 14:35
Distribution: slackware 14

Re: same format all *.desktop files (organize info)

Post#3 by bigbass » 25 Mar 2012, 14:36

Hey brokenman
I'm not sure i understand how this makes parsing .desktop files more efficient. I thought the standard for desktop files was set by these guys:

http://standards.freedesktop.org/deskto ... atest.html
yeah I wasnt trying to say that I will make a new "desktop standard" in that sense
with all the options that we could use that has already been set by those guys at freedesktop.org :)

sorry I just didnt explain things well ( I am glad you posted with a question )
if you look at the new desktops that get made by the script
they are all neat and organized which would allow faster parsing of the info
now that they have a "standard meaning they are all the same now"
the fine guys at t freedesktop.org set a template
well they did but it isnt followed by all package makers
http://standards.freedesktop.org/deskto ... ml#example


Joe

you can test the idea with this if you ran the script above that produced the /tmp/desktops/

Code: Select all

# set this to what you want
fileplace=/tmp/desktops/
filename=audacious2.desktop


desktop_array=( `cat "$fileplace$filename" | tr ' ' '|'`)


echo ${desktop_array[1]//|/ }

echo ${desktop_array[2]//|/ }

echo ${desktop_array[3]//|/ }

echo ${desktop_array[4]//|/ }

echo ${desktop_array[5]//|/ }

echo ${desktop_array[6]//|/ }

echo ${desktop_array[7]//|/ }
#this is here to print the last line

User avatar
brokenman
Site Admin
Site Admin
Posts: 5439
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v3.2rcX all desktops
Location: Brazil
Contact:

Re: same format all *.desktop files (organize info)

Post#4 by brokenman » 25 Mar 2012, 18:02

Ok i understand now. I knew you weren't attempting to create a new standard :) , i just wondered how this increases efficiency of the current system.

After running the script i found it stripped the desktop files of all non-english Comment and GenericName lines. The file i checked was smplayer.desktop. It only keeps the first Comment line.

I guess this does make parsing the file faster ... but it negates support for non-english speakers.
How do i become super user?
Wear your underpants on the outside and put on a cape.

Post Reply