Archive for Apple

SVN, RSS and shell magic on Mac OS X

Bill Bumgarner has a wonderful post on how to setup an RSS feed for a SVN server. This is an interesting approach, especially given how most of my workflow is now RSS based - email, photos, news.

However, the thing that caught my attention was a little command in the midst of his shell scripting:


pbpaste > post-commit

pbpaste isn’t a command I’ve come across before, but one that I looked at and went, “Wow!”.

I’m already a fan of open and have attempted to replicate its behavior on both Windows and KDE to limited success. pbpaste is going to make me miss working on my Mac even more.

pbpaste and its cousin, pbcopy, allow you to redirect the clipboard (PasteBoard) to and from the shell respectively. One of those obvious integration things that makes life a bit easier.

Thanks Apple, you’ve made it harder again to switch away from Mac OS X, and I don’t even have Time Machine … yet.

ADC Core Data Video Tutorial

See here for details on a new tutorial on Core Data.

In the vein of Ruby on Rails style video presentations, you can download the narrated video (38Mb) and learn very quickly how to put together a Core Data application.

Note: for the bandwidth challenged, it is broken down into smaller pieces on the ADC site.

As someone who is largely self taught on the Cocoa side of things, it was instructive to watch another developer at work with Apple’s tools. Aside from learning about Core Data, I learnt some productivity improvements for using Interface Builder and XCode.

If you are writing Cocoa apps, this is well worth a watch!

Elementary Bluetooth using PyObjC

Bluetooth connectivity to devices is supported on Mac OS X using Cocoa APIs, so is possible to access from Python. Bluetooth itself opens up a large body of knowledge that I am only starting to investigate.

This article outlines some basics for using Bluetooth in Python.

Bluetooth access is achieved through two frameworks, IOBluetooth and IOBluetoothUI. Neither of these are included in PyObjC by default, so a basic wrapper class makes life easier. (see the PyObjC docs)

Add the following to IOBluetooth.py:


import objc as _objc

_objc.loadBundle('IOBluetooth', globals(),
  bundle_path=u'/System/Library/Frameworks/IOBluetooth.framework')

The loadBundle pattern is very useful, and allows the classes from any Objective C framework to be loaded into the PyObjC bridge. By putting it into a separate Python module, usage becomes less painful.

For example, the most recent device is:


>>> from IOBluetooth import *
>>> devs = IOBluetoothDevice.recentDevices_(1)
>>> devs[0].getNameOrAddress()
u'gmwils 6600'
>>> devs[0].isConnected()
1
>>>

In this case, my Nokia 6600 is still connected in AddressBook.

To create a new connection to a device, Apple provides access to their user interface for Bluetooth management. It is strongly recommended that these controls are used to provide consistency for the user and detailed error handling.

For example, selecting a service from a device with a dialog:


>>> from IOBluetoothUI import *
>>> browser = IOBluetoothServiceBrowserController.serviceBrowserController_(0)
>>> browser.runModal()
-1000
>>> results = browser.getResults()
>>> results[0].getServiceName()
u'Bluetooth Serial Port'
>>>

Note: you will need a IOBluetoothUI wrapper, similar to the IOBluetooth wrapper from earlier.

Useful documentation links:

Help creating Apple Help

Useful article (via Usable Help) about creating online help for your Mac OS X application, including how to integrate context sensitive help buttons.

Also includes links to some templates (MIT license) to get you started.

Birthday Notes

Birthday Notes is an application with two purposes. On one hand it provides an easy way to keep track of people’s birthdays on Mac OS X. The other role it plays is to learn Cocoa programming using Python, Cocoa and PyObjC.

Why bother with yet another birthday tracking tool? Quite simply, most were too difficult to get the information that I wanted. The main aim of Birthday Notes is to provide a list of upcoming birthdays with relevant information.

For example, I rarely think of people’s birthdays in terms of their birth date (eg 1977-08-04). My brain is wired so that I remember that my birthday is on the 4th of August and that I’m currently 28 and turning 29 on my next birthday. Rather than show the birth date, Birthday Notes shows the birthday and the person’s age they turn on that day.

Birthday Notes features integration to Apple’s existing applications for storing data. This means that iSync support comes for free. The current focus is on a maintenance and reporting tool, so you can edit a person’s birthday from within Birthday Notes, but not create or delete. For additional actions, simply double click on the person’s name - they will be revealed in AddressBook.

I like to know some trivia about people’s birthdays, so Birthday Notes includes a bit of useless astrological information.

Birthday Notes is available for download. Requires OS X 10.4 or greater.

Any thoughts, suggestions, bugs or feedback should be sent to gmwils AT pseudofish.com, or posted in comments on this post.

For those interested in the code, it is available under a GPL license. To compile, Python 2.4, a recent build of PyObjC, and icalendar are needed.

Finally, my thanks to those who have been helping with alpha testing. This release marks the start of a public beta.