Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 28 Aug 2014, 09:42
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Recategorise and rename .desktop files to new dir
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count_1  
Author Message
stu90


Joined: 25 Feb 2010
Posts: 1401
Location: England. Dell Inspiron 1501. Dpup

PostPosted: Mon 30 Jul 2012, 11:20    Post_subject:  Recategorise and rename .desktop files to new dir  

Hello,
I made this script to search for .desktop file categories - then based on the found categories to recategorise and rename the .desktop files to a new directory.

While it does work im wondering if there is some better, quicker more logical way to accomplish this task?

thanks.

# time ~/test
real 0m1.439s
user 0m0.190s
sys 0m0.323s
#


Code:

#!/bin/sh

## convert .desktop file categories and name ###########################

OLDDIR="/usr/share/applications"                 
NEWDIR="/root/applications-new"   
 
   
########################################################################
   
    [[ ! -d "$NEWDIR" ]] && mkdir "$NEWDIR"       
   
function CONVERT () {     
   
    GC=`grep "^Categories=" "$OLDDIR"/*.desktop`
    for FILE in `echo "$GC" | awk -F":" '$2 ~ /\<'"$SEARCH"'\>/{print $1}' | xargs -n1 basename` ; do
   
    if [[ ! -f "$NEWDIR/$MENUCAT-$FILE" ]]; then
    sed "s:Categories\=.*:Categories\=$MENUCAT:g" "$OLDDIR/$FILE" > "$NEWDIR/$MENUCAT-$FILE"
    fi
   
   done
}


## DESKTOP #############################################################
 function DESKTOP () {
   SEARCH="X-Desktop|DesktopSettings|Screensaver|Accessibility|Countryn|X-DesktopCountry|Applets|X-DesktopApplets"
   MENUCAT="Desktop"
    CONVERT
}
   DESKTOP   
   
## SYSTEM ##############################################################   
 function SYSTEM () {
   SEARCH="System|Monitor|Security|HardwareSettings|Core|X-SystemMemory|X-SystemSchedule"   
   MENUCAT="System"
    CONVERT
}
   SYSTEM

## SETUP ###############################################################
 function SETUP () {
   SEARCH="Setup|X-SetupEntry|PackageManager|X-SetupWizard|X-SetupUtilit"
   MENUCAT="Setup"
   CONVERT
}
   SETUP

## UTILITY #############################################################
 function UTILITY () {
   SEARCH="Utility|Viewer|Development|Building|Debugger|IDE|Profiling|Translation|GUIDesigner|Archiving|TerminalEmulator|Shell"   
   MENUCAT="Utility"
   CONVERT
}
   UTILITY   
   
## FILESYSTEM ##########################################################
 function FILESYSTEM () {
   SEARCH="FileSystem|FileManager|X-FilesystemMount|X-FilesystemUtility|X-FilesystemFind"
   MENUCAT="FileSystem"
   CONVERT
}

FILESYSTEM
   
## GRAPHIC #############################################################
 function GRAPHIC () {
   SEARCH="Graphic|Graphics|2DGraphics|3DGraphics|Photography|Presentation|Chart|FlowChart|VectorGraphics|RasterGraphics|X-GraphicUtility"
   MENUCAT="Graphic"
   CONVERT
}
   GRAPHIC   
   
## DOCUMENT ############################################################
 function DOCUMENT () {
   SEARCH="Document|Office|X-Document|WordProcessor|WebDevelopment|TextEditor|X-DocumentUtility|Dictionary"
   MENUCAT="Document"
   CONVERT
}
   DOCUMENT
 
## BUISNESS ############################################################
 function BUSINESS () {
   SEARCH="Business|X-Calculate|Finance|Spreadsheet|ProjectManagement|Calculator|X-CalculateUtility"
   MENUCAT="Business"
   CONVERT
}
   BUSINESS

## PERSONAL ############################################################
 function PERSONAL () {
   SEARCH="Personal|X-Personal|Calendar|ContactManagement|X-PersonalUtility"
   MENUCAT="Personal"
   CONVERT
}
   PERSONAL

## NETWORK #############################################################
 function NETWORK () {
   SEARCH="Network|Dialup|Network|HamRadio|RemoteAccess"
   MENUCAT="Network"
   CONVERT
}
   NETWORK
   
## INTERNET ############################################################
 function INTERNET () {
   SEARCH="Internet|X-Internet|WebBrowser|Email|News|InstantMessaging|Telephony|IRCClient|FileTransfer|P2P"
   MENUCAT="Network"
    #MENUCAT="Internet"
   CONVERT
}    
   INTERNET
 
## MULTIMEDIA ##########################################################
 function MULTIMEDIA () {
   SEARCH="Multimedia|AudioVideo|Video|Player|AudioVideoEditing|Recorder|Music|Audio|Midi|Mixer|Sequencer|Tuner|Video|TV|DiskBurning"
   MENUCAT="Multimedia"
   CONVERT
}
   MULTIMEDIA

## FUN #################################################################
 function GAME () {
   SEARCH="Fun|Game|Amusement|ActionGame|AdventureGame|ArcadeGame|BlocksGame|BoardGame|CardGame|KidsGame|LogicGame|RolePlaying|Simulation|SportsGame|StrategyGame"
   MENUCAT="Game"
   CONVERT
}
   GAME
test.gz
Description  remove fake .gz and make executable
gz

 Download 
Filename  test.gz 
Filesize  3.77 KB 
Downloaded  126 Time(s) 
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count_1  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0500s ][ Queries: 13 (0.0039s) ][ GZIP on ]