Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Extend the power of 'open -a'' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Extend the power of 'open -a'
Authored by: kholburn on Jun 24, '04 07:18:10PM
You'd be better of using "$@" instead of "$command". In fact the script has some wierdnesses. I think an alias would work better here.
#!/bin/sh

if [ $# -eq 0 ]
then
  echo "usage: ${0##*/} <application> <file>"
  exit 1
fi

if open -a "$@" &> /dev/null ; then
  exit 0
else
  echo Couldn\'t launch application \
   \""$@"\" 
fi


[ Reply to This | # ]
Extend the power of 'open -a'
Authored by: jonbauman on Jun 25, '04 01:26:18PM

You're missing half of the point of the script. This version does not honor the argument text edit. The idea behind the script was that I was always forgetting which application names had spaces and which didn't, so I made the script first try with spaces, then try with the spaces collapsed. That way, I can just always type spaces, and it works either way.

As for using "$*" instead of "$@", it's intentional. The former gives all the arguments as one string and the latter as multiple strings. I need them as one string to do the removal of the spaces with "${command// /}". Because "$*" is special, "${*// /}" does not work.

Was there any other weirdness?

---

jon

[ Reply to This | # ]