327Launchd – Reacting to System Events

launchd can be used to montor files and folder and execute certain actions when these files or folders change. Especially useful when an App crashes and writes a log to the CrashReporter. Tutorial, Lingon Helper App

319Chaning Colors in Twitter with the API

require "<a href="http://github.com/jdp/twitterlibphp">twitter.lib.php</a>";
 
$username = "<a href="http://twitter.com/trembl/">trembl</a>";
$password = "&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;";
 
$twitter = new Twitter($username, $password);
 
$options = array(
	"profile_background_color" => "fff",
	"profile_text_color" => "fff",
	"profile_link_color" => "fff",
	"profile_sidebar_fill_color" => "fff",
	"profile_sidebar_border_color" => "fff"
);
 
$update_response = $twitter->updateProfileColors($options);
print_r($update_response);

Nice, isn’t it?

313Swimming Nearly drowning in C++

OK, I’ve decided to do it. To leave the elegance of Objective-C and have a closer look at C++. After all, isn’t everyone doing oF these days?

Here a recapitulation of usesful C and some quick notes on C++ peculiarities – sorry – features: (That might be a good place to start.)

Initialisation
int a = 1; // standard c way
int b(1); // same

Defined constants
#define PI 3.1415927 // faster than var

Declared constants
const int c = 100 // immutable

Assignment
= can also be used as rvalue
a = 1 + (b = 2);

same as:
b = 2;
a = 1 + b;

Comma operator
a = (b=3, b+2); // a = 5

When the set of expressions has to be evaluated for a value, only the rightmost expression is considered

Type casting
int i, j;
float f = 1.234;
i = (int) f;
j = int (f);

sizeof()
One parameter, either a type or a variable and returns the size in bytes.

a = sizeof (char);

Will become important with arrays.

305Converting float to string %4.2f

printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);

floats: 3.14 +3e+000 3.141600E+000

303singleTap: and private API

Very funny and strange case of rejection. I made a method called ‘singleTap’, that is – as the name suggests – receiving events after a single tap occurs.
During the development process the function was not used and commented out, but an oversight let to the notification being left it. And then the message from Apple:

“3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs.”

The following non-public API is included in your application:

singleTap:

Hmm. Clearly I did not use a private API, apparently I just happened to call a function the same name as a private API function… Wondering if there is a list of reserved function names, which is triggered a rejection?

Solution? I commented out the superflicial notification AND renamed the function to ‘oneTap’. Just in case.

I am starting to believe the stories about the Apple store.

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);