View Full Version : Opening a URL in terminal
rickg17
02-07-2002, 06:27 PM
Usually you can use the open command to open an app and, if you want, to specify a file that the app should open, for example, typing
open -a itunes.app ~/music/some.mp3
would launch iTunes and play some.mp3.
However, this does not work for browsers, at least not NS, IE or Omniweb 4.1. Typing
open -a netscape.app http://www.apple.com
does not open apple.com, rather it runs Netscape and then gives this error in Terminal:
No such file: /Users/rickgreg/http:/www.apple.com
I've tried various quoting strategies and eliminating the http:// portion of the URL to no avail. Any ideas?
xchanyazy
02-07-2002, 11:42 PM
The man pages are pretty much useless for this one. The only way I could get it to work was to create a text file with the address in it and name it blah.url. Then, in the terminal, type open blah.url or open -a InternetExplorer.app blah.url. Not very convenient, but if you want to always open the same site, it could be helpful, I guess.
rickg17
02-07-2002, 11:52 PM
Thanks! When I do that though, I get the text file opening in IE, that is, if the text file has http://www.apple.com in it I get that as the page, rather than having it load the apple.com site. The location bar has:
file://localhost/Users/rickgreg/blah.url
in it.
Am I doing something stupid here? (wouldn't be the first time)
xchanyazy
02-08-2002, 12:07 AM
Nope, I'm doing something stupid (definitely not the first time). You have to put two lines in this file:
[InternetShortcut]
URL=http://www.apple.com/
This only works for IE, as far as I can tell. I tried to figure out the way to open a url in Mozilla, but I could only do it by drag/dropping a bookmark to the desktop, and then saying open -a Mozilla.app www.apple.com/
Hope this helps.
rickg17
02-08-2002, 12:47 AM
Sigh.. software is strange. this does not work in IE for me but DOES work in Omniweb 4.1 sp36 and in iCab 2.71.
At any rate, thanks for the help - it's not as clean as just passing a URL on the command line but it will work for me just fine.
thanks again,
xchanyazy
02-08-2002, 12:55 AM
Didn't work for IE? Hmmm...
Well, at any rate, you can try and drag/drop the @ sign in the address bar to your desktop, and then open that file through the terminal, that's how I originally got it too work. However, when I made up my own files with the same format, it worked for me. Bizzare. Oh well, glad I could be of some help.
mervTormel
02-08-2002, 01:11 AM
the truth is that the second arg to the % open command is a file in the filesystem
that that file contains an URL is moot to the first arg of the command
if you have an URL file, like drag an URL from the IE address : [ URL ] , it creates a file with type/creator of "link/msie" and...
% open google.url
will have the desired effect, although a very convoluted way to go about navigating the web.
this brings up a good point, and i'll bet there's a way to do it from shell, it's just not a walk in the park. i tried hand crafting the URL file that IE wants and still got IE opening the local text file showing me the URL data, not the intended site.
what do we want here? something like:
% gwp yahoo.com # alias gwp 'gimmeWebPage'
and kaboom, new page in your browser?
yes, i think that's reasonable.
how to do it? is curl just a fetcher? it's got lottsa knobs and dials...
xchanyazy
02-08-2002, 02:02 AM
Good point mervT,
The reason mine works is because I have changed all .url files to be opened by IE (normal method, just used Get Info..). Didn't realize that until you brought it up...
Fridberg
02-09-2002, 12:44 PM
This is what I did:
alias go "osascript -e 'open location "\""\!:1"\""';osascript -e 'activate app "\""Terminal"\""'"
(this is all one line). Now, you can start your default web browser and open url by typing:
go "http://blah.blah.com"
If you don't want terminal to come to foreground after that, remove everything after semicolon except for last double quotation mark.
1337prophet
04-26-2007, 10:10 PM
haha sorry to dissapoint you all, especially the guy with the reallly long explanation, but it's actually laughably simpler than ALL of your attempts. wanna know how?
open http://www.google.com
^ ^ that opens Google, in your default browser. =D enjoy fellas hahahaha
- Prophet
1337prophet
04-26-2007, 11:05 PM
hahaha, sorry fellas, but the solution is actually LOADS easier than these. sorry to fridberg for his big script too. i assure you (this is for both bash and tcsh) if you type:
open http://www.google.com
it shall open any webpage (here it is Google obviously) in your default browser. Not sure about iTerm, but im almost positive that that would also work similarly. =D enjoy guys!
- Prophet
ArcticStones
04-27-2007, 12:06 AM
.
1337prophet, please consider using a more polite tone in future posts. Make the effort to be helpful without being offensively smug -- it would be much appreciated.
-- ArcticStones
hmmm... on my machine, this format:
open -a firefox http://www.apple.com/
does exactly what's expected - it opens the apple webpage in Firefox. I don't have Netscape installed, but I get the same result with SeaMonkey (Mozilla's new internet suite) and Camino. I'm not sure why this didn't work for rickg - obviously the system thought the apple link was a file specification rather than a valid URI, but the only differences I see are that I didn't use the extension and I added a closing slash. which os X version and version of Netscape are you running? might be a change in the behavior of open, or a limitation of older versions of Netscape...
haha sorry to dissapoint you all, especially the guy with the reallly long explanation, but it's actually laughably simpler than ALL of your attempts. wanna know how?
open http://www.google.com
^ ^ that opens Google, in your default browser. =D enjoy fellas hahahaha
Prophet, that's a direct quote from the man page. good to know you can read, but still... ;)
Craig R. Arko
04-27-2007, 06:07 AM
Hmmm... Strange things happen when people start responding to threads over five years old. Like missing that several major revisions of the OS have occurred in the interim.
Lutin
04-27-2007, 06:55 AM
The positive side effect: It's nice to know that Mac OS X get better and much more simple with time. Just like great wines. ;-)
ArcticStones
04-27-2007, 07:06 AM
The positive side effect: It's nice to know that Mac OS X get better and much more simple with time. Just like great wines. ;-)
Ah, I’m used to fine wine becoming more complex with time, not simpler. ;)
Ah, I’m used to fine wine becoming more complex with time, not simpler. ;)
well, the wine becomes more complex, but drink enough of it and you become simpler. which is maybe what happened here... :D
ArcticStones
04-27-2007, 12:45 PM
well, the wine becomes more complex, but drink enough of it and you become simpler. which is maybe what happened here... :D
True. But I would rather have a bottle in front of me than a Frontal lobotomy. :rolleyes:
fr3nzy
08-07-2007, 08:23 PM
I was in the process of tweaking a Python script, Ruby script, and Bash function to open the Yubnub command entered when I noticed this problem. The open command does not recognize spaces as a part of a URL. To fix this, you have to programatically join the arguments with %20 (the htmlencoded way). E.g.:
# python option 1
import sys
args=sys.argv[1:]
sys.exec("open "+"%20".join(args))
# python option 2
import sys
import webbrowser
args=sys.argv[1:]
webbrowser.open("".join(args)
# ruby
system("open "+ARGV.join("%20")
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.