800Enabling root in OS X 10.7 (or 10.6)

sudo passwd root

After which you are prompted with a

Changing password for root.
New password:

Why the need for root? Surely, it’s a dangerous weapon and things can go awry easily, so only use it as a last resort. (I used it for hiding the couchdb account folder from the GUI.)

703Blocking hosts in /etc/hosts

How to block access to websites on your personal computer. The /etc/hosts file maintains a records of redirects, it you want to block access to a particular site, redirect to your local machine, or whichever site you find appropriate. Not that most website forward host-to-block.net to www.host-to-block.net, so make sure to block the www site as well.

Open the file in your favourite text editor, make sure you have the permissions to open it.

sudo nano /etc/hosts

Add the following line to the file.

127.0.0.1       host-to-block.net
127.0.0.1       www.host-to-block.net

Flush the cache to make the changes immediate.

sudo dscacheutil -flushcache

Again. The crucial bit is to also block the www-site. That seems to be missing from a lot of descriptions/tutorials out there in the wild.

289Simulating Keyboard & Mouse Events. And Key-Modifier Events

Creating and Posting a Keyboard Event:

CGEventRef sDown, sUp;
sDown = CGEventCreateKeyboardEvent (
			NULL,
			(CGKeyCode)1,
			<strong>true</strong>
);
<strong class="red">CGEventSetFlags(sDown, kCGEventFlagMaskShift);</strong>  
 
// setting flags with special function. 
<em>// Setting it via CGCreateKeyboardEvent
// would work only for the first time it's run</em>
 
CGEventPost(kCGHIDEventTap, sDown);
 
sUp = CGEventCreateKeyboardEvent (
			NULL,
			(CGKeyCode)1,
			<strong>false</strong>
);
CGEventPost(kCGHIDEventTap, sUp);
 
CFRelease(sDown);
CFRelease(sUp);

That leaves the door open for applying the same to mouse events:

CGEventRef mouseEvent;
mouseEvent = CGEventCreateMouseEvent (
			NULL,
			kCGEventMouseMoved,
			CGPointMake(100, 100),
			kCGMouseButtonLeft
);
CGEventPost(kCGHIDEventTap, mouseEvent );

Magical. Isn’t it.

Of course, in pre-10.6 days it would have looked like that:

CGPostKeyboardEvent (0,5,true);
CGPostKeyboardEvent (0,5,false);