bash function - open file with application

tdcwilliams

Registered
Hi,
I'm running Mac OS X v 10.5.8.

I would like to be able to write a bash function to do this from a terminal:
open -a /Applications/Adobe\ Reader\ 9/Adobe\ Reader.app "sem.pdf"
(this works fine but is very long).

I tried writing a bash function:
function acroread{
open -a /Applications/Adobe\ Reader\ 9/Adobe\ Reader.app "$1"
}
so that I'd just have to type 'acroread sem.pdf' in future.

However I just got this error:
-bash: syntax error near unexpected token `{open'

If anyone knows what I'm doing wrong here how I'd be greatly appreciative, thanks.
 
Works fine for me, except I put a space between "acroread" and "{".

test.sh:
Code:
function acroread {
	open -a /Applications/Adobe\ Acrobat\ 9\ Pro/Adobe\ Acrobat\ Pro.app "$1"
}

acroread "Test.pdf"

...and I call it like so:
Code:
$ sh test.sh

If you want to just be able to type "acroread somepdffile.pdf" from the command-line, you'll need to remove the function wrapper (just have your script contain "open -a /Applications/Adobe\ Acrobat\ 9\ Pro/Adobe\ Acrobat\ Pro.app "$1""), save the file as a shell script, make it executable ("chmod +x script.sh"), then either put it in a directory that's included in your $PATH, or add the directory where the script is located to your $PATH.
 
Thanks a lot for the tips; the function worked as it was in my bash_profile; good to know you can also do it as a script as well though- I'm sure that'll be useful for longer tasks. Cheers.
 
Back
Top