LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-24-2005, 01:29 PM   #1
daveiro
LQ Newbie
 
Registered: Aug 2003
Location: Funchal, Portugal
Distribution: Fedora 14
Posts: 8

Rep: Reputation: 0
help on shell script as a wrapper to launch default programs according to input file


Hello!

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:

file:/home/myusername/path/to/file.that.can.have.dots.before.extension.pdf

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:

Code:
#!/bin/bash
PDFPROG=/usr/bin/acroread
ODTPROG=/usr/bin/oowriter

PATH=`echo $1 | awk -F'file:' '{print $2;}'`
$PDFPROG $PATH
But it's not working

I try this

Code:
fmlaunch file:/home/david/actual/academico/Phd/bibliografia/function/bickhard/ErrorDynamics.pdf
and I get this:

Code:
/usr/bin/acroread: line 8: ls: command not found
/usr/bin/acroread: line 8: sed: command not found
/usr/bin/acroread: line 9: dirname: command not found
/usr/bin/acroread: line 17: dirname: command not found
/usr/bin/acroread: line 102: dirname: command not found
/usr/bin/acroread: line 109: dirname: command not found
/usr/bin/acroread: line 117: ls: command not found
/usr/bin/acroread: line 117: sed: command not found
/usr/bin/acroread: line 118: expr: command not found
ERROR: Cannot find installation directory.
I wonder if it's because acroread is also a script?
 
Old 11-24-2005, 04:08 PM   #2
tlowk
Member
 
Registered: Nov 2003
Location: Belgium
Distribution: Slackware
Posts: 151

Rep: Reputation: 23
#!/bin/bash
PDFPROG=/usr/bin/acroread
ODTPROG=/usr/bin/oowriter

FILEPATH=$(echo $1 | sed 's/^file://')
EXTENSION=$(echo 1 | sed 's/.*\.//g')

case "$EXTENSION" in
'pdf')
$PDFPROG "$FILEPATH"
;;
'odt')
$ODTPROG "$FILEPATH"
;;
*)
xmessage -buttons 'ok:1' "unknown type $FILEPATH"
;;
esac

#end
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

regards,

tlowk
 
Old 11-24-2005, 04:20 PM   #3
daveiro
LQ Newbie
 
Registered: Aug 2003
Location: Funchal, Portugal
Distribution: Fedora 14
Posts: 8

Original Poster
Rep: Reputation: 0
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

gnome-open

in Freemind prefs and Gnome automagically opens the default app for the file tha I clicked in Freemind.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script pipe input - bash mostly laikos Programming 4 11-09-2008 05:14 PM
how can I take input with a shell script? GUIPenguin Linux - General 4 04-11-2005 03:46 PM
Shell script user input tuckermaddox Linux - Newbie 5 08-12-2004 03:14 AM
Opening file with default application from shell script? bourbon_beast Programming 4 04-13-2004 01:52 AM
can't launch java app from shell script... LonAllen Linux - Newbie 0 07-07-2003 08:37 AM


All times are GMT -5. The time now is 05:00 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration