HOW TO: start your default web browser with one unix command

alligatorTim

Registered
kind of silly i know, but i edit html in my term windows and i hate using a mouse to test in a browser.

short version:
--------------------------
1. make an html page. (page.html)
2. write an executable shell script somewhere in your $PATH with the line "Open /path/to/page.html;".
--------------------------

long version:
--------------------------
fisrt create a nice little html page. mine looks like this..

PHP:
<html>
<title>alligatorTim</title>
<body bgcolor="#ffffff">
hello alligator.
</body>
</html>

but you can do anything you want within the boundrys of client side web content. once you create your html page name it "mypage.html" and put it in your home directory. (/Users/yourname)

now open a terminal and type "cd /usr/bin" then, using your favorite unix text editor create a file with the following line:

Open /Users/yourname/mypage.html;

you will have to run the editor as the super user (using sudo) because root owns /usr/bin. so for example "sudo pico zong". name the file something catchy and easy to type because the name of this file is gonna be the command you type to launch your browser. i used "zong".

finally. once you've saved your new file and exited your editor. you need to type "sudo chmod a+x zong".

now when you type "zong" at the command prompt it will launch your page in your default browser.
--------------------------
 
Umm...why would you write a shell script to do that? You could just type open /Users/yourname/mypage.html and it would work fine. Or are you just going for a one word command? I guess that's helpful....
 
Or you could setup your site (/Users/<you>/Site == http://localhost/~you. Create and index.html page and at its simplist create a list of all the pages you are createing with anchor links to them. Then work on your html files that are in ..../Sites/<optional subdirs>.

This way you can use the html pages as if they are on a Web server (which they now are), rather than the reduced functionality you have when opening pages on the normal file system. For example, if you have php setup, you html, I mean php pages can contain PHP code and will work correctly, but won't if handled outside of the webserver. You also have access to the cgi-bin thru the Web Server.

I hope that helps!

Cheers,

Brooke
 
And NEVER, NEVER (did I say NEVER) put your scripts in /usr/bin.

Use ~/bin or /usr/local/bin for your stuff. I really makes it much easier to backup and restore if you know what is yours and what is owned by the system.

Brian G.
 
Back
Top