gcmd-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gcmd-dev] python: mimetype plugin


From: Magnus Stålnacke
Subject: Re: [gcmd-dev] python: mimetype plugin
Date: Fri, 02 Feb 2007 13:29:53 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20051003

Micha wrote:


Some month ago, Magnus posted a shellscript providing a very rudimentary mimetype editing interface.

Uhh, almost a year a go, time passes...


@ Magnus, would you re-post the latest version of your script ?

Attached is my latest from March 2006. I had allmost
forgot that i wrote it. This is one of those things
one uses to set things up, and then it is, and later
does not require any more attention.

#!/bin/bash
#
# Umime - a script for chosing prefered applications. 
# Written by Magnus Stålnacke (jemamo at telia.com) 
# Version 0.3 (26 Mars 2006)
#
# TODO
# Add "runs in terminal" option
#
export LANG=en_US.utf8 
XDG_DATA_DIRS=$HOME/.local/share
DEFAULT=$XDG_DATA_DIRS/applications/defaults.list
G_CACHE=/usr/share/applications/mimeinfo.cache
U_CACHE=$XDG_DATA_DIRS/applications/mimeinfo.cache
MTPE=`file -i $1 | awk '{print $2}'`
EXT=usercreated.desktop
#

function deflist (){
G_AVAIL=`grep "$MTPE" $G_CACHE | sed -e 's/.*=//g;s/;$//g;s/;/\n/g'`
U_AVAIL=`grep "$MTPE" $U_CACHE | sed -e 's/.*=//g;s/;$//g;s/;/\n/g'`
for i in $G_AVAIL; do
NM=`grep "^Name=" /usr/share/applications/$i | sed -e "s/Name=//g;s/ /_/g"`
echo "$NM $i off" >> /tmp/avail
done
for i in $U_AVAIL; do
NM=`grep "^Name=" $XDG_DATA_DIRS/applications/$i | sed 's/Name=//g;s/ /_/g'`
echo "$NM $i off" >> /tmp/avail
done
#
# Change no to yes for the alredy set user default app. 
#
if grep -q "$MTPE" $DEFAULT 
then
DEF_APP=`grep "$MTPE" $DEFAULT | sed "s|$MTPE=||g"`
cat /tmp/avail | sed "s|$DEF_APP off|$DEF_APP on|g" > /tmp/avail
fi
#
dialog --radiolist "Please select" 20 74 11 `cat /tmp/avail` 2> /tmp/chosen
retval=$?
choice=`cat /tmp/chosen`
clear
case $retval in
0)
  DEF_CH=`grep "$choice" /tmp/avail | awk '{print $2}'`
  if grep -q "$MTPE" $DEFAULT
  then
    cat $DEFAULT | sed "s|$MTPE=.*|$MTPE=$DEF_CH|" > $DEFAULT
    DEF_MESSAGE="Default application to handle $MTPE is changed to $choice"
  else
    echo "$MTPE=$DEF_CH" >> $DEFAULT
    DEF_MESSAGE="Default application to handle $MTPE is set to $choice"
  fi;;
1)
  echo "Cancel pressed.";;
255)
  echo "ESC pressed.";;
esac
rm -f /tmp/avail
rm -f /tmp/chosen
}

function modmime(){
GLOB_USER=`cat $U_CACHE $G_CACHE`
USER_APP="$XDG_DATA_DIRS/applications/$APP-$EXT"

if echo "$GLOB_USER" | grep "$MTPE" | grep -q "$APP"
then
  M_MESSAGE="The mime type: $MTPE is alredy assigned to: $APP"
  deflist
else
  if [ -e "$USER_APP" ]
  then
    cat $USER_APP | sed "s|MimeType=|MimeType=$MTPE;|g" > $USER_APP
    M_MESSAGE="The mime type: $MTPE is now added to: $APP"
  else
    echo "[Desktop Entry]" > $USER_APP
    echo "Encoding=UTF-8" >> $USER_APP
    echo "Name=$NME" >> $USER_APP
    echo "MimeType=$MTPE;" >> $USER_APP
    echo "Exec='$CMD'" >> $USER_APP
    echo "Type=Application" >> $USER_APP
    echo "Terminal=false" >> $USER_APP
    echo "NoDisplay=true" >> $USER_APP
    M_MESSAGE="The application: $APP is now registered to handle: $MTPE"
  fi
export XDG_DATA_DIRS
update-desktop-database -q
deflist
fi
}

#
# Ask the user for app. command and check the command.
#
function wrong (){
  dialog --inputbox "No such command in path, try assign command with full 
path" 20 74 2> /tmp/chosen
APP=`cat /tmp/chosen`
rm -f /tmp/chosen
check
}
function check (){
if which $APP >&/dev/null
then
  CMD=`which $APP`
  modmime
else
wrong
fi
}
function chcmd (){
dialog --inputbox "Write the command to start the application $NME" 20 74 2> 
/tmp/chosen 
APP=`cat /tmp/chosen`
rm -f /tmp/chosen
check
}

#
# Ask the user for app.Name
#
dialog --inputbox "Write the name of the application you wish to register \
as able to handle the mime type: $MTPE, or press cancel if you only want to \
set the default application to handle this mime type." 20 74 2> /tmp/chosen 
if [ -s /tmp/chosen ]
then
NME=`cat /tmp/chosen`
chcmd
rm -f /tmp/chosen
else
deflist
fi
#

echo "** $M_MESSAGE"
echo "--"
echo "** $DEF_MESSAGE"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]