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

Open URLs from the command line in OmniWeb Web Browsers
The command line program "open" is weak in that it doesn't work on URLs, even if they are put in proper form (i.e. with a preceding http://). To provide this missing function, I built a quick shell script that takes any number of URLs as an argument and then opens them concurrently in Omniweb. An added bonus is that the URLs are sent as if they were typed in the Omniweb address bar, so any completion options work. The script follows:
#!/bin/sh
# sends a string to be parsed by the Omniweb browser

if [ -z "$1" ]
then
echo "usage: ow URL ..."
exit 65
fi

until [ -z "$1" ]

do
osascript -l AppleScript -e "Tell application \"Omniweb\" to getURL \"$1\""
shift
done &
exit 0
So now, "ow google hats" opens a browser window in the background with a google search for the word hats.

[Editor's note: To make the script executable, make sure you issue a "chmod 755 ow" and then "rehash" (or close and open the terminal). Enter the text using vi or pico or any other text editor that will not add Mac line breaks.]
    •    
  • Currently 1.83 / 5
  You rated: 2 / 5 (6 votes cast)
 
[3,857 views]  

Open URLs from the command line in OmniWeb | 9 comments | Create New Account
Click here to return to the 'Open URLs from the command line in OmniWeb' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A small correction
Authored by: Black on Jun 04, '02 10:14:03AM

The way this script is written, it tries to parse each argument separately. So, the example command at the bottom won't work as advertised, it will first open www.google.com and then it will try to open www.hat.com

The correct command, using this script would be
ow "google hat"



[ Reply to This | # ]
ow: Command not found.
Authored by: sjonke on Jun 04, '02 10:56:47AM

That\'s all I ever get when I try to run ow as such: ow \"someurl\"
This does work: ./ow \"someurl\"

I\'ve always seen this problem with shell scripts I create. What is causing this? I hate having to type in the \"./\" Yes, I did the \"chmod 755 ow\"



[ Reply to This | # ]
ow: Command not found.
Authored by: robg on Jun 04, '02 11:22:43AM

Where do you save the scripts? Make sure they're somewhere in your path; I use ~/bin for the shell scripts I create. You can see the path with "echo $PATH".

If you store stuff there (or elsewhere on your $PATH), it will run just fine.

-rob.



[ Reply to This | # ]
ow: Command not found.
Authored by: rer on Jun 04, '02 01:55:15PM

Make sure you put the file somewhere in your path. Your home directory is not typically in your path, but the bin directory in your home directory usually is. If you want to find out what your path is set to, type 'set' in a terminal window. If this doesn't entirely make sense, let me know and I'll try again.



[ Reply to This | # ]
To change focus to the page
Authored by: Leibowitzn on Jun 04, '02 03:18:38PM

Add this line :
osascript -l AppleScript -e "Tell application \"Omniweb\" to activate"



[ Reply to This | # ]
cron
Authored by: SeanAhern on Jun 04, '02 11:13:11AM

Try running this from cron. My guess it osascript will fail with a message saying that it can't get the application's dictionary.

I've written a similar script and have had that problem. I have some ideas on how to get around it, but haven't worked on it much, yet.



[ Reply to This | # ]
better - just use
Authored by: bhines on Jun 04, '02 05:49:45PM
There is an app called "launch" in Fink that will be much faster than this. launch lets you do: launch -l http://www.cnn.com/ "fink install launch" to get it. (it's even in the stable tree) Or you can get it from its web site:
launch-1.0a9-2: Replacement for OS X "open" command.
 launch is a replacement for "open" which:
 * Opens URLs, directly or in your preferred helper application.
 * Lets you specify applications by their four-char creator (e.g. 'ToyS') or Java-style
  bundle ID (e.g. com.apple.scripteditor), both of which allow you to move or rename an app.
 * Asks applications to print documents, something the OS X Finder is missing.
 * Launches applications in the background, or launches Carbon applications in Classic.
 * Shows info about any item on disk, including its file type, creator, data and resource fork sizes, dates and bundle ID.
 .
 Web site: http://web.sabi.net/nriley/software/


[ Reply to This | # ]
launch works for me
Authored by: Titanium Man on Jun 05, '02 12:37:14AM

I couldn't get the Applescript to work, but got launch to work. Here are a few possiblities of things you can do (launch will open them in your specified default browser):

#! /bin/sh

launch="/sw/bin/launch"
echo="/bin/echo"
sed="usr/bin/sed"

launch -l http://www.google.com/search\?hl=en\&q=$(echo "$*" | sed 'y/ /+/')


#! /bin/sh

launch="/sw/bin/launch"
echo="/bin/echo"
sed="usr/bin/sed"

launch -l http://whatis.techtarget.com/wsearchResults/1,290214,sid9,00.html?query=$(echo "$*" | sed 'y/ /+/')


/sw/bin/launch -l http://www.dictionary.com/search\?q="$*"

The first two shell scripts will look up a string on Google and Whatis.com respectively. The 'sed' bit takes spaces from your search string and inserts a + which is how it would appear if you had typed in a search string on the website. The last bit can be used as an alias to look up a word at dictionary.com (ie:
alias stupidalias='/sw/bin/launch -l http://www.dictionary.com/search\?q="$*"'
for bash or
alias stupidalias '/sw/bin/launch -l http://www.dictionary.com/search\?q="$*"'
for tcsh) Just my 2 cents.



[ Reply to This | # ]
Built-in for Jaguar
Authored by: Cloudscout on Jun 04, '02 06:18:02PM
The ability to launch URLs from the command line will be built in with Jaguar. The ability to click telnet:// and ssh:// URLs in your browser and have them automatically launch in Terminal will also be included.

[ Reply to This | # ]