Posts Tagged ‘osx’

Cocoa for Ruby(ists) with MacRuby

Tuesday, October 28th, 2008 by Thilo Utke

Apple’s Application Framework Cocoa gained popularity recently, also due to the iPhone. Like many others we started to learn Objective-C to play around with the iPhone a couple of months ago. The basic syntax is fairly easy to learn, also because lots of sources exist to get you up and running. But in my opinion the real challenge is to understand how the interface builder works

The past

But as a Rubyist the C like syntax of Objective-C was quite a pain. So I didn’t enjoy working with Objective-C. The existing Ruby bridge RubyCocoa has its own drawbacks. Especially moving parameter names into the method name to mimic Objective-C’s keyed arguments doesn’t appear future proof to me. This all kept me from getting deeper into the subject.

The future

In March this year MacRuby made its appearance as a successor for RubyCocoa. MacRuby is a port of Ruby 1.9 on top of the Objective-C runtime and garbage collector, which aims to fix all of the RubyCocoa drawbacks and bring the full power of Ruby to the Cocoa framework. With the 0.3 release a couple of weeks ago, MacRuby now supports the Interface Builder, thus making it a full fledged member of the OS X Development tool chain. Since then MacRuby gained serious popularity. An official Apple Developer Connection Tutorial for “Developing Cocoa Applications Using MacRuby” was published recently. More good tutorials can be found on the web, so I just link to them instead of writing another.

During the weekend I went through the first chapters of “Cocoa Programming for Mac OSX” with MacRuby instead of Objective-C to get familiar with the Cocoa library and Interface Builder. It went super smooth so far, I really had fun. Here is just a short example of the very first app out of the book to see how the code compares to objective-c.

class Foo
attr_writer :text_field

def seed(sender)
@text_field.StringValue = “Generator doesn’t need to be seeded ;)
end

def generate(sender)
@text_field.StringValue = (rand(100) + 1)
end
end

^ Ruby vs. Objective-C v

@interface Foo : NSObject
{
IBOutlet NSTextField *textField;
}

- (IBAction)gerneate:(id)sender;
- (IBAction)seed:(id)sender;
@end

@impelemtation Foo

- (IBAction)generate:(id)sender
{
int generated = (random() % 100) +1;
[textField setIntValue:generated];
}

- (IBAction)seed:(id)sender
{
srandom(time(NULL));
[textField setStringValue:@"Generator seeded"];
}
@end

As you can see you don’t need a header file and much less special characters. It even gets better, because you don’t need to call [[NSMutableArray alloc] init] but Array.new or just [] to initialize an empty Array. Isn’t Ruby beautiful? And with MacRuby you can have it for your Cocoa Apps too. So jump on board.

TextMate Snippet Power für gettext

Sunday, February 17th, 2008 by Thilo Utke

Es ist super wenn die Werkzeuge, die man verwendet mit einem wachsen. Deshalb bin ich von Ruby und TextMate begeistert.

Für die, die TextMate nicht kennen: TextMate ist ein TextEditor für OS X, der sich in meinen Augen durch zwei Besonderheiten als Entwicklungswerkzeug hervortut. Erstens die leistungsfähige Live-Suche, die alle Mausklicks zum Navigieren im Projekt überflüssig macht. Zweitens die wirklich mächtigen Skriptingmöglichkeiten, die ich wohl noch lange nicht erfasst habe.

Jedenfalls musste ich Rahmen der Internationalisierung eines Projekts alle Strings in eine Übersetzungsmethode von gettext wrappen. Also ggf. Texte in den Views in Inline tags und in doppelte Anführungszeichen zu packen. Das gewünschte Ergebnis sieht etwa so aus: <%= _("Zu übersetzender Text") %>. Die ganze Arbeit ist ziemlich stupide, ließ sich aber mit TextMate auf simples Markieren des entsprechenden Textes und das Drücken des Tastenkürzels ctrl+alt+t reduzieren.
(more…)

Grafikeffekte im Terminal

Tuesday, December 11th, 2007 by Alexander Lang

Nie mehr Langeweile auf der Shell, einfach iTunes Visuals in den Hintergrund gelegt und schon pulsiert die Kommandozeile. Es lebe die Erfindung des halbtransparenten Fensters:


.

Perian: DivX & Co. für Quicktime

Thursday, April 19th, 2007 by Alexander Lang
macbookfrontrow.jpg

Perian ist eine freie Quicktime-Komponente für OSX, die Formate wie DivX, XviD abspielen kann. Zusammen mit Flip4Mac kann Quicktime somit nun endlich die meisten Filme und Formate abspielen. Das ging zwar bisher mit VLC auch, aber durch Quicktime ist das ganze doch wesentlich besser integriert: der Finder hängt sich beim Versuch, einen DivX-Film in der Vorschau anzuzeigen, nicht mehr auf und endlich kann man die ganzen Streifen auch mit Fernbedienung und Front Row genießen.