World According to Jussi

Mar 13 2009
+

Applescript is as fun as a massacre

I may have communicated my hatred towards AppleScript previously but let’s recap.

AppleScript does not fit the model a programmer’s brain is used to. It has terrible documentation and it seems to just fight against you. Part of the problem is not AppleScript per se, but the application dictionaries, but from the end user’s point of view the guilty party is not relevant, in the end the experience just sucks.

Today I rewrote a script I had written years back, mainly because I had lost the script somewhere. Writing less than 30 lines of easy AppleScript to integrate iTunes and QuickTime Player took more than 30 minutes and was at least as frustrating as it was years back. To help the future me I document some basic things below. They are very easy to read, but much harder to write while fighting the AppleScript.

Get currently playing track in iTunes

set t to current track

Get first of currently selected tracks in iTunes

set t to first item of selection

Get the alias of a track

set loc to location of t

Get the play position (in seconds) of iTunes

set pos to player position

Set the play position in QuickTime Player

-- d is the document, pos is the wanted position in seconds
set ts to time scale of d
set current time of d to ts * pos
Sep 19 2008
New Nokia goodness coming soon?
+
Finnish and Swedish languages are so alike :) (from youtube comments of Microsoft’s I’m a PC ad)
Finnish and Swedish languages are so alike :) (from youtube comments of Microsoft’s I’m a PC ad)
Sep 15 2008
Jukeboxbabe showed how he records eastern threat. This is another view to that matter.
Jukeboxbabe showed how he records eastern threat. This is another view to that matter.
Apr 11 2008
+

WWDC here I come!

Yes, it’s true! I’m going to WWDC this year, and I’m planning to visit Canada at the same time. If you want to check my flights, just subscribe to a iCal feed at http://flightagenda.com/1e085835-cd2c-460a-a3ef-251f9bae86da.ics 

I will update all my future flights there so if you happen to be at the same town at the same time just contact me and we’ll grab a beer. :)

Mar 08 2008

Update on Cocoa

It has been a long time since last post, lots have happened both in my personal life and in the wonderful world of Cocoa.

For about 6 months I have been working daily with Cocoa it has been very pleasant and I still learn a lot every day.

With the release of Leopard a few months ago Objective C got updated to 2.0, which brings lots of nice changes. Perhaps properties and garbage collection save more time, but the new for loop syntax is my absolute favourite.

But frankly the new Interface Builder just makes me smile every time I use it it is *so* much better.

So, this was a small update I hope to be blogging a bit more frequently in the future.

Jul 08 2007

Holiday and PyObjC

Hello, all my imaginary readers :)

Sorry for the months of silence. That has been caused by my work at an unnamed Finnish mobile phone maker. It has unfortunately taken almost all of my time and after the work I have not felt too enthusiastic to do any coding. This has meant that the nice Cocoa project I and a friend were working on last spring has been on hibernation, it will stay like that until the fall, at the minimum.

Those were the bad news, but thankfully I’ve got some good news too. Tomorrow (Monday) will be the first day of my holiday. I’m going to spend most of my holiday in the Netherlands and France. I hope it will be a nice counterbalance to the (dull) life in Finland.

A few weeks ago I had written a small but useful download-the-pic-from-an-opened-flickr-page script in Python. It had worked quite well, but frankly the usage had been quite unsophisticated. The script was 100% console based.

Yesterday I decided it was time to make a GUI for it, just a simple one. The work was actually done in 3-4 LOC using EasyDialogs module. I was quite impressed with myself but in about 2 minutes I had to admit that the UI sucked, even more than the console UI.

I felt almost betrayed, but thought that I could invest a bit more time. There were some Carbon based options for Python, but I wanted a proper GUI and use Cocoa via PyObjC. This showed to be the correct choice. After a few missteps, like trying to compile PyObjC myself, I got adapted to the PyObjC way of doing things and it was working quite smoothly.

No compilation means faster edit-test process. In a way using Cocoa API via Python was even better than the real thing, for example there was no explicit alloccing and initting strings needed, I could just introduce a Python string and and use it transparently in place of an NSString.

But there is a caveat: the ObjC style method names of Cocoa are mangled into Pythonesque names with underscores. For instance sending a message

[anObject message:a using:b and:c]

becomes

anObject.message_using_and_(a, b, c)

Also delegate names are mangled in the same manner:

- (void)applicationWillTerminate:(NSNotification *)notification {}

becomes

def applicationWillTerminate_(self, notification): pass

I found that to be quite ugly, but it works and I guess I could get used to that with time.

In conclusion, PyObjC was a pleasant experience with a some drawbacks. I’m probably not going to use it to make “real” applications, but it seems to be a perfect fit to adding a proper GUI for an existing Python script.

May 06 2007

Cocoa == Productivity

Today I was productive, mostly thanks to Cocoa. The praise for the framework is well earned, apart from a few exceptions.

I worked on a simple UI for a Cocoa app. I must say that the experience was mostly pleasing, simple things were easy to do and the help material to do some a bit more advanced things was both good and easy to find with Google.

I would be in heaven if only Xcode and Interface Builder were a bit more stable. I had a brief frustration with a possible gcc bug, but I’ll double check that tomorrow.

Page 1 of 2