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: Select all
#!/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