Since I last posted almost a month ago now, promising to expand on my comment that one component had reached a semi-usable state, I have neglected to pay any attention to this blog other than occasionally thinking ‘yes, I really need to make that post’. Rest assured that I have not been quite so lax with bene itself.
One of the buzzwords of the moment, and what looks to be a movement with an increasing momentum within the open-source community (even stretching itself into the GNOME project), is that of the document-oriented desktop.
This is opposed to the traditional application-oriented desktop in which the program is the key. Application-oriented designs are the sort of thing developers would come up with; they’re constantly looking for ways to tweak things, so nothing should be hidden.
The focus of document-oriented desktops is to minimise the amount of conscious interaction between the user and the program in favour of leaving the user to simply get on with working with his documents. The theory is that it promotes greater usability and efficiency; the user doesn’t think of how to work with their program but instead how to work with their data. No longer does the user think of Evince or epdfview or Acrobat; they think of ‘a PDF viewer’.
Likewise there is increasingly an attempt to increase the dynamism of the desktop, with recognition that old static models just don’t cut it any more. Thus there is a move away from manual saving and undo/redo histories towards applying a revision control system to every document, with ‘milestones’ taking the place of the old save system. The aim is to minimise data loss and maximise workflow. Then there are many other potentially world-changing ideas; it really is a whole new paradigm.
I’m hoping that bene can take the best parts of these ideas. That’s the point, really.
The first component of bene I wrote was a shell script to open specific files using specific applications, part of a move towards a document-oriented environment. It really bothers me that I can’t choose to open just this file in Gnumeric, just this file in gedit.
I’m an A-Level student who makes notes for politics and physics using his laptop. I use ODT almost exclusively as my file format for these notes; however, I really don’t need the overhead of Openoffice.org Writer in politics lessons; I don’t need the power of OO.o just to make notes. So I use Abiword for politics notes.
But on the other hand, I do need the power of OO.o for physics lessons. I need embedded spreadsheets and diagrams and equations in my documents; Abiword can’t do all of this.
The problem is when we continue notes from previous lessons; I can’t just double-click a file in the file-browser when I’m in politics because Writer is set as the default application for opening .odt files. I find it quite frankly shocking that in the year 2009 we’re still unable to choose to open a specific file by default in a different application to other files of its type.
That’s the point then of this first bene module; to open a file using the specified application. It has very little error-handling at the moment, and the code’s not as clean or elegant as it could be. It’ll be improved though.
#!/bin/bash
## This script opens a file with the appropriate application, which might be different for some files than others, even of the same type. Thus one might want to open the vast majority of PNG images in an image viewer such as gthumb, but open photos from a wedding in the GIMP.
## Import necessary code
source core/bene-settings-manager.sh
## Assign the first argument to the command variable
command="$1"
## Assign the second argument to the file variable
file="$2"
## Create the config file if it does not exist
if [ ! -e $HOME/.bene/bene-applications ]; then
echo "Configuration file not found"
echo "Attempting to create file"
create_file="$HOME/.bene/bene-applications"
## Inherited from core/bene-settings-manager.sh
_create-config-file
fi
echo "$command"
_open-file () {
## Check to see if the file has been opened before; identify it by the inode number so it's not affected by changes in path
inode="`ls -i $file | cut -d " " -f 1`"
if [ ! `grep "$inode" ~/.bene/bene-applications | sed -e "s,${inode}|[^|]*,${inode},"` ]; then
echo "File has not been opened before, adding to config file"
echo "Choosing an application to open with"
_get-app
_set-file-new
fi
## Take the application for this file from the config file
application=`grep "$inode" ~/.bene/bene-applications | cut -d '|' -f 2`
## Launch the application for the file
echo "Opening $file with $application"
$application $file
## If the inode number should change when the application closes then update the inode entry in the config file
echo "Updating the inode number"
newinode="`ls -i $file | cut -d " " -f 1`"
sed -i -e "s,${inode}|[^|]*,${newinode}|${application}," "$HOME/.bene/bene-applications"
}
## Function to get the application to open a file with using Zenity GTK dialogs
_get-app () {
## Set the default application to be xdg-open so it's opened with a suitable application if a specific one isn't chosen
application="/usr/bin/xdg-open"
## Choose between opening with a specific application or the default
choice=`zenity --list --radiolist --text="What do you wish to open this file with?" --column Option --column Action 1 "Use the default application to open it" 0 "Open this file with a specific application"`
## Choose the application for this file if it was chosen to use a specific application
if echo $choice | grep "specific"; then
application=`zenity --entry --title="Choose application" --text="Please enter the path of the application you wish to open this file with.
Use '/usr/bin/xdg-open' if you wish to use the default application."`
fi
}
## Function to insert a new entry into the config file
_set-file-new () {
## Echo the file's inode number and the application, seperated by |, into the config file
echo "$inode|$application" >> "$HOME/.bene/bene-applications"
}
## Function to change the application associated with a file
_reset-file () {
inode="`ls -i $file | cut -d " " -f 1`"
echo "getting app"
_get-app
sed -i -e "s,${inode}|[^|]*,${inode}|${application}," "$HOME/.bene/bene-applications"
}
## Function to delete a file and app from the config file
_delete-file () {
inode="`ls -i $file | cut -d " " -f 1`"
sed -i -e "s,${inode}|[^|]*,," "$HOME/.bene/bene-applications"
sed -i -e '/^$/d' "$HOME/.bene/bene-applications"
}
if [ "$command" == "--open" ]; then
echo "Opening $file"
_open-file
elif [ "$command" == "--delete" ]; then
echo "Deleting $file's entry"
_delete-file
elif [ "$command" == "--reconfigure" ]; then
echo "Reconfiguring $file"
_reset-file
else
echo "Command not recognised"
exit
fi
exit