• 02Sep
    Categories: Apple, Development Comments Off

    I need a lot of desktop space as shown in the picture below.

    My Desktop

    Apart from my main hackintosh with dual 22″ monitors, I have a mac mini running linux with a 17″ monitor to the left for all my terminal work, and on the other side, I have a 17″ G4 iMac just for IRC. I have an RSS feed in one of my channels, so I tend to click on links in that, but Safari on the G4 isn’t the fastest thing around, so I decided to pull some Remote Apple Events tricks out of my hat so as to load links in Safari on my main machine instead.

    How I did it was to put the following into Applescript Editor, and save it as an Application Bundle (replacing the user, pass and ip/hostname in the second line) :

    on open location theurl
    	set dest to "eppc://user:pass@ipaddress"
    	tell application "Safari" of machine dest
    		activate
    		open location theurl
    	end tell
    end open location
    

    But for an application to handle URLs and be able to be set as the default browser, you have edit the Info.plist file inside the “Contents” folder of the app bundle and add the following:

    <key>CFBundleIdentifier</key>
    <string>com.pawz.openbrowser</string>
    <key>CFBundleURLTypes</key>
    <array>
    	<dict>
    		<key>CFBundleURLName</key>
    		<string>Remote Opener</string>
    		<key>CFBundleURLSchemes</key>
    		<array>
    			<string>http</string>
    		</array>
    	</dict>
    </array>
    

    Next, you have to tell OSX to refresh the launchservices info by running this command (which I’ve broken up into three commands just so it fits on this page) and replacing with the path to your app:

    cd /System/Library/Frameworks/CoreServices.framework
    cd Frameworks/LaunchServices.framework/Support
    ./lsregister -v -f /path/to/my.app
    

    Lastly you need to enable “Remote Apple Events” in the “Sharing” panel of System Preferences on your “destination” computer. Now, you can load up Safari on the “source” computer and change the default browser to be your Applescript application and close Safari again. Now, when you click on links in any application, it will contact the remote computer, bring Safari to the foreground, and load the URL. Isn’t that just *awesome* ?

  • 28Apr
    Categories: Development Comments Off

    I had a hard time recently while setting up my latest Asterisk + FreePBX install. Outbound calls worked fine, but GoTalk’s server wasn’t even contacting my Asterisk box to route incoming calls. I ripped through 3 versions of asterisk and many reinstalls before I discovered the cause. GoTalk need a slightly more convoluted register string than normal. Once I entered the special register string, it registered and received calls fine. If you’re looking for a GoTalk config for Asterisk with the help of any of the guis, use this:

    Outgoing Settings

    Trunk name: GoTalk

    Peer Details:

    host=sip.gotalk.com
    authuser=09xxxxxxx
    username=09xxxxxx
    secret=YNxxxxxx
    type=peer
    fromuser=09xxxxxx
    fromdomain=sip.gotalk.com
    canreinvite=no
    insecure=very
    qualify=yes

    Incoming Settings

    User Context: 09xxxxx

    User Details:

    username=09xxxxx
    fromuser=09xxxxx
    type=peer
    secret=YNxxxxx
    insecure=very
    host=sip.gotalk.com
    fromdomain=sip.gotalk.com
    context=from-pstn

    Register String:

    09xxxxxxx:YNxxxxxxx:09xxxxxx@sip.gotalk.com:5060/09xxxxxx

    After this, just add your inbound route with 09xxxxxx as your DID and divert it to a local extension and you should be in business ! Hope this helps you avoid some hair-pulling.

  • 28Apr
    Categories: Development Comments Off

    I recently switched from using flat zone files to mysql zones using the MySQL Bind SDB Driver to put all my zone records into a database, which lets me update zone records and see the dns changes immediately without needing to reload bind. Unfortunately, one of my sites is a dynamic beast that generates the site based on the subdomain, and if the subdomain doesn’t exist, optionally run an install script to create that subdomain. As such it relied on bind9 wildcard dns to resolve the subdomains. However, even though the the MySQL SDB Driver supports wildcard dns, it has a bit of a flaw in the way it parses the domain name. When given unknown.domain.com it would attempt to resolve *.unknown.domain.com when it should in fact be looking for *.domain.com, which means that lookups for a wildcard record fail.

    As such, I waded neck-deep into the Mysql SDB Driver source in order to come up with a fix, and I emerged with the following patch file:

    wildcard.patch

    Unpack the MySQL Bind SDB Driver source and cd to the mysql-bind directory and patch the file with the following command:

    patch -p0 < /path/to/wildcard.patch

    Then follow the MySQL Bind SDB Driver Installation Document as per usual to add the drivers files to bind and configure bind as normal.

    Wildcard records should be specified in the form *.domain.com and should always be A records as wildcarding a CNAME is not recommended. When a record lookup fails now, it will look for a wildcard record and if found, return that record.

  • 20Feb

    In Linkinus, you can get the currently playing iTunes track info by typing /itunes, which is all well and good, but what if you have a beautiful g4 iMac dedicated to IRC, but you play your music on another computer ? Alas, all is lost ! O wait, no it isn’t, all you have to do is enable “Remote Apple Events” on the computer with iTunes (in sharing, in system preferences) and then open up ~/Library/Application Support/Linkinus 2/Scripts/itunes.scpt and make the following changes:

    1. Change:

    	tell application "Finder"
    		if (get name of every process) contains "iTunes" then set itunes_active to true
    	end tell

    To:

    	set itunes_active to true

    This will stop it checking on the local computer for iTunes. Next change:

    	tell application "iTunes"
    		if player state is playing then
    			set theTrack to name of the current track
    			set theArtist to artist of the current track
    			set theAlbum to album of the current track
    			set theBitrate to bit rate of the current track
    			set theKind to kind of the current track
    			set theRating to rating of the current track
    			set theStream to current stream title
    			set got_track to true
    		end if
    	end tell

    To:

    	set dest to "eppc://username:password@hostname"
    	using terms from application "iTunes"
    		tell application "iTunes" of machine dest
    			set theTrack to name of the current track
    			set theArtist to artist of the current track
    			set theAlbum to album of the current track
    			set theBitrate to bit rate of the current track
    			set theKind to kind of the current track
    			set theRating to rating of the current track
    			set theStream to current stream title
    			set got_track to true
    		end tell
    	end using terms from

    … and lo and behold, you’re getting your iTunes track info from the remote computer instead. Geek points +1 for today.

  • 30Jan
    Categories: Development Comments: 1

    I come from a PHP background as a web developer, so when I started learning Objective C, one of the first programs I tried to write was an RSS reader since I had plenty of data laying around in MySQL tables. I googled for MySQL frameworks for Cocoa/Objective C and only came up with one, MCPKit, formerly called SMySQL by Serge Cohen and available on his site at http://mysql-cocoa.sourceforge.net/. Unfortunately the framework available from there is old and compiled only for PPC, not Intel. Since then, someone called glimberg has put a Universal Binary version of the earlier SMySQL project online at http://code.google.com/p/mysql-cocoa-framework/, However I believe this framework is broken as I found it wouldn’t return more than one column of data. I contacted some of the developers of the project Sequel Pro as they were the only people I knew of who used MCPKit in their application and they were very helpful and told me how to compile their more updated and fixed version of MCPKit that they bundle with their application. I did, and finally the framework sprang to life. I’d like to share with you how to install the framework and how to write a simple GUI application that displays query results in a table. I have a database of RSS news items that I want to display in a scrollable table.

    Install the framework into your project

    The best guide to this is this one written by Serge himself. I’ve stored it here in case it goes missing from his site like his examples and other code. I recommend you read it and follow the instructions to the letter to avoid linking errors.

    Include the framework

    In your main App Controller’s header file, include the framework’s headers:

    #import <MCPKit/MCPKit.h>

    Setup your database variables

    In your header, define the variables we’re going to use to store the connection handle, the results, and the array we use.

    MCPConnection *db;
    MCPResult *result;

    Connect to your database

    The syntax for connecting to the database is very easy. The authors of Sequel have changed the way passwords are handled in their version of MCPKit to support connecting via keychain, so here’s how it’s done:

    db = [[MCPConnection alloc] initToHost:@"hostname" withLogin:@"username" usingPort:3306];
    [db setPassword:@"yourpassword"];
    NSLog(@"Connect: %d", [db connect]);
    NSLog(@"SelectDB: %d", [db selectDB:@"ismyhome"]);

    Running Queries

    Queries are easy to perform and results can be retrieved as an array or an NSDictionary which is quite useful. If you’re used to PHP, you’ll use queryString instead of mysql_query and fetchRowsAsArray and fetchRowsAsDictionary instead of mysql_fetch_array and mysql_fetch_assoc like you’re used to. In my example here, I just use fetchRowAsArray.

    NSArray *row;
    result = [db queryString:@"select Title, Link from newsitems LIMIT 10"];
    while (row = [result fetchRowAsArray]) {
    	[rss addObject: [row objectAtIndex:0]];
    }

    tableview

    Creating an NSTableView

    OK so you’ve got some data, how do you output it ? In your header, create a tableView outlet.
    IBOutlet NSTableView *tableView;

    Now in Interface Builder, drop in an NSTableView and an Object for your AppController. Click twice on the middle of the table so the TableView is selected (as opposed to the ScrollView), then right click and connect the dataSource and delegate methods to your AppController so it looks as shown in the screenshot to the right. To link our IBOutlet to the NSTableView, right click your AppController and link the tableView outlet to your NSTableView you just created.

    Provide data to your NSTableView

    To provide your NSTableView with data you must implement two protocol functions as shown below:

    -(int)numberOfRowsInTableView:(NSTableView *)tv {
    	return [rss count];
    }
    -(id)tableView:(NSTableView *)tv
    		objectValueForTableColumn:(NSTableColumn *)tableColumn
    		row:(int)row {
    	return [rss objectAtIndex:row];
    }

    Download the the working framework

    As mentioned, I found both the versions of MCPKit/SMySQL floating around on Serge’s page and the google page to be broken, so I’m providing here a copy of the Universal Binary compiled framework as compiled from the latest Sequel Pro 0.9.7 source. If you need to recompile the framework for any reason, I suggest getting their source below. To compile it you just need to select the MCPKit target and build.

    Sequel Pro Source Code – download

    Latest MCPKit (build 1218) – download

    Getting Help

    Since Serge is no longer maintaining this project it’s hard to find support for it. If you’re looking for other users of the framework, try the authors of Sequel Pro who can be found in #sequel-pro on Freenode. Thanks to avenjamin for helping me with some linking errors I was having and putting me on the right track.