help on shell script as a wrapper to launch default programs according to input file
I'm using marvellous program Freemind, see freemind.sourceforge.net/wiki/index.php/Main_Page, everyone should find this program useful for lots of daily tasks!
It's a Java program and it allows us to launch an external program where the first parameter is a path of a file. In Linux it defaults to konqueror which is not good to open files like OpenOffice.org documents or Adobe PDFs in a user-friendly way, since I'm using Gnome as default desktop.
So I thought on using a shell script to parse the file received, detect the file extension and then launch the corresponding program.
I have very little experience on shell scripting so I ask for help on how to do this.
The script receives a path with this format:
So the script will have to extract what's on the right of : (this I already think it's working)
Then it will have some kind of WHILE command to go trough the string to find the extension, save it in some variable, then have something like a CASE that for predefined extension types will then launch the corresponding program.
Here's what I got until now:
I try this
FILEPATH=$(echo $1 | sed 's/^file://')
EXTENSION=$(echo 1 | sed 's/.*\.//g')
case "$EXTENSION" in
xmessage -buttons 'ok:1' "unknown type $FILEPATH"
use double quotes for variables that can contain spaces (even better don't use spaces
in a file or directory name at all)
and don't use PATH since it can block other scripts if you use it with export, also it makes the script less readable
Thank you for your help on the script! :)
On the second echo you forgot a dollar sign right?
Meanwhile I found another alternative, one just needs to use the command
in Freemind prefs and Gnome automagically opens the default app for the file tha I clicked in Freemind.
|All times are GMT -5. The time now is 09:37 AM.|