3/12/14

How To Edit The Hosts File On A Mac To Actually Block Sites


The Hosts file on a computer basically is like a phone book that you create that your computer checks to see if a URL should go someplace other than what a DNS server tells it too. You can tell your computer to load duckduckgo whenever anyone types in google or just to block all google access entirely.

You can think of it as a website, address, domain blocker as well. The problem is that most advice and how-to's on the internet regarding how to edit it on a Mac to block things is actually quite wrong. Sometimes so wrong that it won't block anything.

Most searches will return some method of editing the Hosts file via the Terminal. It works, doesn't require anything else to download and once you memorize a few simple commands it's not a big deal.

But there's a more familiar way if you just take a few moments to set it up.

1. Head to BareBones.com and download the free text editor TextWrangler.
2. Install it where you want. The Applications folder is a good place.
3. Put the icon in your dock or leave the Applications window open so you can see TextWrangler's icon.

Why are we using TextWrangler instead of something that comes with the Mac like TextEdit? It has to do with how the text in the hosts file is encoded. TextEdit doesn't really play nicely with the encoding in the hosts file because the hosts file is, to put it simply, a special kind of file. It's not just a simple plain-text file, and TextWranger knows how to handle this slightly different kind of file. 

4. Hit Command + Shift + G for Go To in the Finder. An Open dialog will appear.
5. In the "Go to the Folder" text entry box type or paste in (without the quotes) "/private", just /private then hit Return. We do this this way because the folder "private" is hidden by default and we need to access a folder that's inside of it.
6. Look for a folder called "etc". Option + Drag it to your desktop to create an alias of it. (this is optional, but helps if you plan on altering your Hosts file frequently. If everything has gone correctly you now have an alias to "etc" on your desktop.
7. Double Click the etc alias to open it.
8. Tap the letter H to get close to the hosts file and scroll down if need be until you see a file simply named "hosts".
9. Now this file is a little different than files you deal with on your Mac day to day. It has a few permissions about who can access it set differently than files you created or use most of the time. That's okay, this is why we're setting all this up. It's fairly error-proof.

Okay, so now to edit the hosts file DRAG it on top of the TextWrangler application icon and let TextWrangler open it. It will very likely ask for your admin password. That's okay. It's asking because the hosts file is protected from inadvertent changes and it just wants to make sure you're you and you really want to change it.

 ##  
 # Host Database  
 #  
 # localhost is used to configure the loopback interface  
 # when the system is booting.  Do not change this entry.  
 ##  
 0.0.0.0     localhost  
 255.255.255.255     broadcasthost  
 ::1             localhost   
 fe80::1%lo0     localhost  
That's great. We're almost there.

Keep in mind this type of address blocking is just for this computer, the one where the hosts file actually resides, not your home network. That's for another post or you can just use a free domain blocker like OpenDNS which lets you block up to 50 domains for free, I think.

Let's say we want to block on this particular computer a website (or ad site, or music site, or spam site) called reallybadwebsite.com for whatever reason.

10. In TextWrangler directly under the last line start a new line (just like a regular word processing document) and type this:

0.0.0.0 reallybadwebsite.com

(note: that's a single space between the zero -those are ZEROS by the way- and the website url)

11. Hit save and enter your password if it asks. It asks because hosts being a special file it's protected from inadvertent changes. But since this is your computer and your password and your account it's okay. So now you have something like this:

 ##  
 # Host Database  
 #  
 # localhost is used to configure the loopback interface  
 # when the system is booting.  Do not change this entry.  
 ##  
 0.0.0.0     localhost  
 255.255.255.255     broadcasthost  
 ::1             localhost   
 fe80::1%lo0     localhost  
 0.0.0.0 reallybadwebsite.com  

And you just saved it. Guess what? You're done.

Try loading that address and it shouldn't work. Your web browser should complain that it can't find the site anymore. Why is this happening?

Your computer is checking this file to see if reallybadwebsite.com is listed there, it finds that it is and then looks where it should go, in this case an IP address of 0.0.0.0 which is now where. Spiffy, eh?

Some tutorials will insist you use the Terminal and I'll briefly explain that below. But you'll often see them mention something like this:

127.0.0.1 reallybadwebsite.com

With a TAB in-between the number and the address.

It turns out that 127.0.0.1 on a Mac isn't really a reliable place to send an address. Sometimes, believe it or not, the Mac will still figure out how to get to the address. It kind of says, "Oh that IP address is being used for something else already, so I'll just check a DNS server and see where else that address should go." It's just trying to help. Sending an address to all zeros sends it into a black hole.

Close TextWrangler and you're done, done.

Next time you want to edit the hosts file just open up the alias to "etc", drag the hosts file on top of TextWrangler and edit away.

THE TERMINAL:

I used to do it this way but over time I'd forget the exact commands or a computer would use a different type of editor and commands would change so I'd get confused but here's the basic idea:

- Launch the Terminal which is in /Applications/Utilities/

- Type in exactly (or copy paste)
sudo nano /private/etc/hosts

- Hit return and type in your administrator password and hit return. It won't show your password as you type, btw.

- The hosts file will be loaded but you'll have to use the arrow keys (no mouse) to get the cursor where you want it.

Type away.

- When you're done hit the key combo Control + O then Return, this will save the changes you made. 

- Hit Control + X to get out of the text editor in the Terminal.

- Now quit the Terminal. You're done.

NOTE FOR LION USERS:

I haven't test this but I've seen a few replies on message boards saying that adding the 0.0.0.0 address.com at the end of the hosts file doesn't work in Lion. 

What apparently works is adding it AT THE VERY TOP of the file, even above the double-hash "##".

CONTROL + COMMAND + D Dictionary Command Not Working In Safari

I'm sitting in front of Safari 5.1.10 on a Snow Leopard system on a long road trip and noticed on a few sites that I visit hitting the key combo of Control + Command + D which brings up a handy pop-up dictionary didn't work. I had lots of time to hurry up and wait on this trip so I decided to find out why.

Short version: It seems to be caused by substitution fonts injected into a page from another source. In the few cases I looked into it is caused by typekit.com not playing nice with OS X's Services.

Long version:

Control + Command + D is a Service, and oddly, one that's not listed in System Preferences > Keyboard > Services, that brings up a handy pop-up dictionary definition of the word the cursor is currently over. I use it very often in my research.

It works on some sites and not others and it turns out the culprit are services that replace the font on a page with another "universal" one. A popular site that supplies these fonts is typekit.com.

Here's how I stopped it, but in the process made some web pages slightly less...refined looking.

Method One:

Edit your host file to block the offending site, in this case typekit.com. See my post about how to properly edit your hosts file here.

Method Two:

Use a free service like OpenDNS to block the offending domain.

Method Three:

Block the Javascript that accepts the font code from the offending site.

There are many many ways to block Javascripts but for Safari a free and fairly easy way is JavaScript Blocker you can get for free here.

1. Load up the offending site.
2. Click on Javascript Blocker's button in your Safari Toolbar and look for

use.typekit.com

and

typekit.com

Block both scripts and reload the problem page and test the dictionary short cut. Javascript Blocker provides a way to just block the script temporarily in case it causes a problem. If it seems to be working, make it permanent (you can always change it later) and you should be good to go.

The only issue I've noticed so far with this is that web sites that use custom fonts won't look as intended but I actually think they're often (but not always) more legible with the font script blocked.


3/14/13

How to Fix Box Sync's Finder Crashes and Missing Sync Icons

This is for OS X 10.6.8 and BoxSync 3.3.51.

Box Sync (from Box.com) seems to have a bug caused by a Safe Boot of the Mac where after a normal boot -after a Safe Boot- BoxSync will cause the Finder to crash and relaunch after BoxSync, well, syncs.

Also, all the overlay icons like the checkmarks and orange syncing icons will be gone.

It's a bug in BoxSync and here's how to fix it.

0. Quit BoxSync from the Menubar by clicking on the "b" and selecting Quit at the bottom.

Now quit all the apps that are running. Yes, all of them.

1. Download Onyx from here. (be super-sure you get the right version for your version of Mac OS X)
2. Launch it.
3. Let it run it's initial SMART and Verification checks which may take enough time to make some coffee and get a snack. You can just hit Cancel twice if you want to but it's a good idea to let it run these checks.
4. Enter your Admin password.
5. Click on "Automation"
6. Un-tick everything except "LaunchServices" and "dyld's shared cache" under Rebuilding.
7. Hit "Execute" (if you didn't quit all apps before step 1 you'll have to to continue now anyway)
8. Let Onyx do it's thing.

Reboot. Seriously.

After the Mac is booted you should have seen the Finder NOT CRASH when Box Sync launched and synced. If you missed it, that's okay.

9. Now, go to System Preferences (from the Apple Menu is the easiest way generally) and then click on "Box Sync" then click on "Sync Now".

The Finder shouldn't quit and relaunch. That's good!

But your overlay sync icons in Box Documents in the Finder may still be missing. That's bad.

10. So, in System Preferences in Box Sync click on "Settings..."

11. Then hit "Force Uploads". And see if your overlay sync icons return. If no, hit "Force Downloads" and see. One of them should cause them to return.

Done.

2/25/13

Stop Sites from Tracking You in Safari

There are three things you can try alone or simultaneously to make browsing in Safari fairly private that, while not making you untraceable on the web, will keep most places from tracking you.

Try these and see how they work for you. They can break some web sites functionality so experiment and see. They're all very easily undone if something goes wrong.

A. Lock The Cache

1. Quit Safari.

2. Head to Macintosh HD > Users > YOURACCOUNT > Library > Caches > com.apple.safari

Inside this folder you'll see "Cache.db".

3. Delete Cache.db (highlight it and hit COMMAND + DELETE, then Empty your trash with SHIFT + OPTION + COMMAND + DELETE).

4. Restart Safari.

5. Look in the com.apple.safari folder for a newly created Cache.db file. It should be about 25 KB in size if empty. Get Info on it (highlight it and hit COMMAND + I) and check the "Locked" check box then close the Get Info window.

Safari will no longer store anything in it's cache.

To Undo this just unlock Cache.db. But quit Safari before you unlock it so Safari doesn't get confused.

B. Lock Local Storage

Think of the LocalStorage folder as a folder full of web cookies. They're essentially the same thing and can potentially track your movements on the web similarly to cookies.

1. Quit Safari.

2. Head to Macintosh HD > Users > YOURACCOUNT > Library > Safari

3. In this folder you'll see a folder called "LocalStorage". Empty it, delete anything and everything within it.

4. Like locking the Cache.db file above, Get Info on the LocalStorage folder itself and check the Locked checkbox.

5. Relaunch Safari.

Safari will no longer store LocalStorage cookies.

C. Keep A Fresh Copy of A Clean Cookie File

Cookies store identifiable information and some persist for years. Unfortunately without cookies enabled many many sites simply won't work. Blame advertisers.

So we need to allow cookies generally but here's a slightly complex way to keep them from tracking you for any length of time you don't deem appropriate.

1. Write down all the passwords for sites you regularly visit on some paper or in a TextEdit document (don't save it if you're worried about security, just work with an unsaved document). This step is important.

2. Quit Safari.

3. Head to Macintosh > Users > YOURACCOUNT > Library > Cookies

In here you'll see "Cookies.plist". This is where all your cookies are stored from sites you like and trust to  useless advertisers.

4. For a safety backup, Right-Click on Cookies.plist and select "Compress Cookies.plist". This will create a .zip compressed file of your cookies that you can easily restore if something goes wrong, right there conveniently in the Cookies folder. To keep things tidy rename it something like "Cookies.plist_ORIGINAL" or something so you'll know later on this is your original Cookies file with zillions of junk cookies in it and your old settings and account info.

Looking at a command line tool called fs_usage I've seen Safari touch this zip file from time to time. I'm not sure it's looking in the contents of this file but if you're concerned that Safari can look inside the .zip file just move it to a different location. 

Alternatively you can password protect the .zip file. This isn't a one-click procedure but requires use of the command line in the Terminal but it's not terribly difficult at all but I'll post about compressed zip files later or you can search for it.

5. Trash the actual Cookies.plist folder. Empty the trash.

6. Launch Safari.

7. Now, methodically, go to every website you like and log-in and configure them. It's likely you'll be a little surprised just how different websites and accounts and prefs at sites are without cookies.

The trick here is to just go to sites you regularly visit. Mainly ones that require log-ins or you've configured. Don't go to any sites that don't apply. We're building a clean Cookies.plist file here.

8. Once you're done Right-Click on your new clean Cookies.plist file and Compress it. Rename it something like "Cookies.plist_CLEAN" and keep it there or someplace you'll remember.

9. Now that you have a clean cookies file all you ever need to do when you want to eliminate cookies that you don't want and just use cookies that you do want is Quit Safari, go to this folder, Trash and Empty trash on Cookies.plist, then double click Cookies.plist_clean.zip and you're good to go.

Pro Tip: Go to Safari's preferences and look at your cookies under the Privacy tab to see how many cookies you have, where they are from and other things anytime along this process. You'll maybe be shocked by how many cookies you have and to which sites they belong.

BONUS TRACKING TIP:

Safari likes to keep previews of webpages you've visited. Previews, as in saved images of the sites. It's where Top Sites and visual history get their images from rather than pulling them from the web all the time. It's a process called Safari Webpage Preview Fetcher and there's a post on it here.

If you turn off Top Sites in Safari's prefs it usually stops part of the process and saves some CPU but visual history still can save images of sites you go to. Ya know, sites like your bank account, your email, things like that.

Head to Macintosh HD > Users > YOURACCOUNT > Library > Caches > com.apple.safari

Now in here look for a folder called "Webpage Previews".

As before, Get Info on it and Lock it.

Test all of this out to see if it impacts your web browsing. So far the only negative to all of this is slightly slower load times on sites because Safari doesn't cache anything and pulls a full, complete fresh web site every time but it's nothing I really notice.

Give these suggestions a try and see how they work for you and remember that each is easily undone if something isn't to your liking.

5/19/11

The Outer Limits and Roswell

While I'm thinking about it, there was a book published recently called "Area 51: An Uncensored History of America's Top Secret Military Base" by Annie Jacobsen.


In the book the author tells us that (from Geekologie):

"Jacobsen tells sources who revealed that not only did one of these flying craft crash in the U.S. in '47, but the Hortens were involved, the flying "saucer" had hover-and-fly capabilities unheard of in any aircraft of the day, and contained two surprise pilots: children believed to be about 13.

And from where did these young pilots come? Not from space.
"The child-sized aviators in this craft were the result of a Soviet human experimentation program," Jacobsen said, making a point that this was information from an eye-witness source and one she trusts completely, "and they had been made to look like aliens à la Orson Welles' War of the Worlds" using "genetic and surgical" procedures.
What's worse: that's not even why Area 51 is classified. As in, Soviet-modified children-turned-alien-pilots who crash landed in a saucer isn't atrocious enough. It's secret because apparently American officials saw these tests and decided to conduct human experiments of their own."

Which, to me sounded familiar:

The Architects of Fear (aired in 1963)

Another good link about this episode is here.

"The world has entered a Cold War-esque setting in which nuclear holocaust appears imminent. In the hope of staving off an apocalyptic military confrontation between nations, an idealistic group of scientists, working at United Labs, plan to stage a fake alien invasion of Earth, in an effort to unite all humanity against a perceived common enemy. The scientists have managed to study the planetary conditions on the planet Theta. They draw lots, and physicist Dr. Alan Leighton is chosen to undergo radical surgical procedures that will transform him into a projected figure from a planet with a different atmosphere. Leighton's death is faked and the bizarre series of transplants and modifications to his body proceed. His wife Yvette persists in not believing he is dead, she feels sympathetic pain as Alan suffers on the operating table. Complications arise when the effects of Leighton's transformation extend beyond physical appearance and begin to affect his mind, a situation compounded by the scientist's strong psychic link to his pregnant wife.
The scientists' plan is for Dr. Leighton as the Thetan creature, equipped with a energy weapon and spaceship, to land at the United Nations in an effort to create panic initially, that will be resolved as the world unites to fight the invader. Alan, now a perfect simulation of an inhabitant of the planet Theta, is launched into orbit as a weather satellite but the mission goes awry when the spaceship comes down off course and lands in the woods near the United Labs facility. After disintegrating their station wagon with his laser pistol, the doctor is severely wounded by three duck hunters with shotguns and he stumbles back to the lab. Yvette again feels his pain and hurries to the lab looking for her husband, she arrives as the Thetan enters and collapses to the floor. Before dying of mortal wounds, the creature demonstrates "the mark against evil", a personal gesture they both shared and Yvette realizes the horrifying truth that the alien is in fact her husband."

It's also not an original idea.

Nor obscure.

Doctor Who vs. The Outer Limits

Doctor Who aired an episode called Smith and Jones back in 2007 where:

"The episode sees the Doctor (David Tennant) meeting Martha Jones (Freema Agyeman), a medical student at Royal Hope Hospital. The hospital is transported to the Moon, whereupon the Doctor and Martha must contend with a Plasmavore posing as Florence Finnegan (Anne Reid), as well as the Judoon (voiced by Nicholas Briggs), who are hunting for Finnegan."


Which always seemed familiar to me somehow until I recently ran across this:


A Feasibility Study an episode of The Outer Limits from 1964 in which:


"Residents in a city suburb awake one morning to find their neighborhood has been transported to another planet the previous night. The intention of the aliens is to study the feasibility of enslaving the entire human race to do manual labor on their planet. But the aliens must overcome humanity's susceptibility to its diseases, and the willpower of mankind's resistance to slavery."


While not exactly alike, it's similar enough that the Doctor Who episode seemed familiar to me.

3/4/11

Stolen Windshield Wipers

In Polanski's first film "Knife in the Water" (1962, shot in Poland) the married couple worries that their windshield wipers will be stolen as they go out on their boat and leave their car unattended. At the end the wipers are stolen and it's never explained.

So looking around online I found two interesting reasons why this is happening today.

One is Ravens. Apparently some people claim that the birds steal the rubber parts to use for nesting material. The confusion here is that some people call the whole thing, metal and all the wiper, while others call just the rubber part the wiper.

Two are lock picks. People make lock picks out of the strong yet flexible metal that holds the rubber wiper.

There. Mystery solved.

A third reason would be likely the same reason people take things like this: as a gag. It's unlikely you'll notice they're gone (on some cars anyway) until you need them.