Objective-C Proper Class init

Proper Objective-C init for classes.

- (id)init; { if ((self = [super init]) == nil) return nil;

[***initialize any necessary code]; return self; }

Cocoa Recipes updated


Recently I noticed that one of my favorite books for learning cocoa was updated to it’s second version.  Cocoa Recipes for Mac OS X (2nd Edition) is a hands on approach to teaching cocoa. The orginal Cocoa Receipes was conceived from a web site  from the same author called Vermont Recipes.  This book is one of the best books for driving home some real world learning after finishing Aaron Hillegass book Cocoa(R) Programming for Mac(R) OS X (3rd Edition).  There is nothing better to learning cocoa concepts than actually writing code especially as part of an actual application.

The entire book takes the reader through development of one complete project. The reader follows along as the author adds new features to the application one chapter at a time.  The author takes the time in each chapter to explain what is happening.   I referenced the Vermont Recipes extensively (before the book came out) when I first picked up cocoa and still find it useful today. The new version is updated to reflect the changes in the recent Snow Leopard OS X release.
As a side note I should mention that I do not know the author personally or compensated in anyway for writing this post.  Bill Cheeseman is a very active member of the Cocoa community and can be seen on the Apple mailing list.  Also, as of this writing, Amazon’s look inside the index is from the old version.




SerialChannel channel changing software updated

Recently I updated my SerialChannel and SerialChannelIR applications for EyeTV and Directv.  These new versions provide several new features as well as bug fixes and performance improvements.  SerialChannel now supports cable boxes in addition to Directv.  It also overs a new ethernet connection options which allows a user to change the channel through an ethernet connection.  The latter option allows the Mac to be located in another room away from the directv box without running wires. To get more info go to www.cooldvr.com

Learning C programming with Cocoa

After almost 12 years of C  programming under my belt I often find myself answering questions from people asking me how to get started.  Most will ask what I think is the one single book to read when learning how to program in C or do I need to know C before I learn other C languages such as Objective C and C++.  There are many avenues to learning how to write in C which can often leave a new comer feeling overwhelmed. However, I think there is one approach that works well and provides a step wise approach to learning C.  Oddly enough, it does not envolve learning traditional C directly.  Learn to program in Apple’s Cocoa language and ease into traditional C.

For the most part, there is not one book.  Usually it takes 3 or 4 really good books to get a handle on C programming. Each book provides its own unique aspects to teaching, skipping some topics while covering other in depth.  One of the things that I like about using Cocoa as a starting point is instant gradification.  Using Cocoa(R) Programming for Mac(R) OS X (3rd Edition) as a learning tool can provide the new comer with a good sense of how programming works.

Cocoa is apple’s native way to program for the Mac.  Cocoa utilizes Objective-C as its underlying language.  Objective C is a Object oriented sub set of C much like C++.

While Cocoa is a great language it is almost impossible to be really good at it or any C dialect without knowing C.  So Why learn Cocoa First?  In short Arron Hillagas’s Cocoa Programming on Mac OS X

One of the things you will notice is that there are not a lot of books on Cocoa. However, the completeness of Cocoa(R) Programming for Mac(R) OS X (3rd Edition) and the style of Cocoa makes it easy to learn and deduce.  The Cocoa language is so well done syntactically it is very conducive to teaching and Aaron’s book is it’s perfect complement. In my opinion there is not one single book on any language that is as complete from beginner to intermediate as this book.  When you read the text and follow the examples to the end it will leave you comfortable with the language and wanting to learn more into the intermediate level.  With all that said, there are a few must have books that build on the knowledge learned from Aaron’s book.

If you are interested in learning C through Cocoa here is a list of books I would recommend (In order of learning level). Go here for an easy link to each.

  • Cocoa(R) Programming for Mac(R) OS X (3rd Edition)
  • Learn Cocoa on the Mac (Learn Series)
  • Programming in Objective-C 2.0 (2nd Edition) (Developer’s Library)
  • Learn C on the Mac (Learn Series)
  • Cocoa Programming
  • Mythbuntu 8.1 tweaks

    Run Mythfilldatbase automatically.

    In mythtv frontend menu.

    • Utilities/Setup -> Setup ->  General. On the 6th screen enable “Automatically run mythfilldatabase”. In arguments it is a good idea to use –refresh-all to force a refresh today or two days (or every day) from now, to catch the latest changes

    Commercial Skipping

    In myth frontend menu:

    • Utilities/Setup –>Setup -> TV Settings -> Playback and select “Automatically Skip Commercials”. on the 8th Screen

    Reduce Latency in Channel Changing

    In mythtv frontend menu:

    1. Utilities/Setup –>Setup –> TV Settings –> General. On the first screen select “Change channels immediately without select”.
    2. Utilities/Setup –> Setup –> TV Settings –> Playback OSD deselect “Always use Browse Mode”

    Disable DPMS screen power saver:

    prompt$ vi ~/.xsessionrc

    prompt$ cat ~/.xsessionrc

    xset s noblank

    xset s off

    xset -dpms

    Now restart desktop so changes take effect

    $ sudo /etc/init.d/gdm restart

    If you are looking to connect your Mac’s EyeTV application to a set top box such as Directv, Dish Network, Sky Boxes or virtually any other box there are several low cost options that make it easy.

    If you have Directv you have 3 options

    1.  SerialChannel.  SerialChannel provides a reliable and clean installation. It works through a serial or ethernet connection that connects to the usb or data port of your Directv box.

    2.  SerialChannelIR. SerialChannelIR is an Universal IR blaster solution for the mac.  It uses USB-UIRT and an IR blaster cable connected to the front of your box to mimic your box’s remote to change channels.

    3. eyeChange. eyeChange is designed to work with ethernet enabled Directv boxes. Most of the Directv HD boxes now have ethernet ports which can be connected to a home network. No wires necessary. Now available in the app store.

    Which ever one you choose will provide a seamless channel change from EyeTV to your box.

    If you have Dish Network or virtually any other box use SerialChannelIR.

    If you have a standard Sky digibox, Sky+, Sky HD, Foxtel iQ (but not Foxtel iQ2) or Foxtel Pace 420 you also have two options.

    1.  SerialChannelSky.  SerialChannelSky provides a reliable and clean installation.  It works with Dusky-control hardware to change the channels on your box.

    2.  SerialChannelIR.

    See www.coolDVR.com to get more info.


    If you have used Xcode before you know that when you create a new project the name you give the project is used as the name for the target executable.  But what do you do if you come up with a new name for your application or want to create a similar project with some minor changes.  Well you have two choices.

    1.  Rename the entire project.

    2.  Rename only the executable.
    Update: XCode 3.2.3 now provides a built in rename. Open the project you want to rename in Xcode then under Projects select rename.

    Renaming a project in Xcode 3.x

    This seems like it ought to be a simple process provided by Xcode but it is not.  Here is how to do it.

    1.  Copy and rename the project folder

    2.  Inside the new project folder rename the files ending in .pch and .xcodeproj

    3.  Right click on .xcodeproj file (it is actually a folder) and select show contents. In the contents folder there should be a file ending in .pbxproj. Open This file in you favorite editor and replace all instances of the old project name with the new project name.

    4.  Delete the build folder

    5.  Open the Renamed Xcode project and right click (Control click) on the Target from the groups and files list. Select Info to open the properties panel.

    6.  Click on the build tab the select packaging from the collection pop up menu

    7.  Change the value in the product name build setting to the new name.

    8.  Do Build Clean all Targets.

    Changing the executable name

    1. Open the Xcode project and right click (Control click) on the Target from the groups and files list. Select Info to open the properties panel.

    2.  Click on the build tab the select packaging from the collection pop up menu

    3.  Change the value in the product name build setting to the new name.

    4.  Do Build Clean all Targets.

    Mythv and Pretty File Names For Recordings

    When you record something on mythtv it creates a entry in the database and names the resulting recorded file.  However, if you were to look in the recordings directory you would see that the given name is a bit hard to figure out.  In this post I will show you how to create a directory that holds links to these files with user friendly names.  In Mythbuntu there is a script which does most of the work for us. We’ll then share that directory on a network via SAMBA and NFS

    1.  On your myth box open a terminal window (or ssh into the myth box).

    2.  Change directory to /home/mythtv and create a directory called readable-recordings.

    prompt$ cd /home/mythtv

    prompt$ sudo mkdir readable-recordings

    3.  Change directory to /usr/share/doc/mythtv-backend/contrib and locate the file named mythrename.pl.gz.

    prompt$ cd /usr/share/doc/mythtv-backend/contrib

    Unzip the file:

    prompt$ sudo gunzip /usr/local/bin/mythrename.pl.gz

    Make the file executable:

    prompt$ sudo chmod a+x /usr/local/bin/mythrename.pl

    Move the file decompressed file to /usr/local/bin:

    prompt$ sudo mv /usr/share/doc/mythtv-backend/contrib/mythrename.pl /usr/local/bin



    4.  Run the script with the –link option:

    prompt$ /usr/local/bin/mythrename.pl --link /home/mythtv/readable-recordings

    The files in the readable-recordings directory should be easy to read with the proper episode name and title of the recording.

    5.  Setup the script to run automatically.   This script works great but does not run automatically so we need to schedule it with cron to do this hourly.

    prompt$ sudo nano /etc/crontab

    Create the following entry to run the script every hour:
    0 * * * * /usr/local/bin/mythrename.pl --link /home/mythtv/readable-recordings

    5.  Sharing the readable-recordings. From the MythUbuntu Control Center select services from the right side menu.  You should see options to enable NFS and SAMBA sharing directory.   Then go to the desktop Applications –>System–>Shared Folders.   The shared folders application will appear with functions locked.  Click on the unlock button to allow editing.  Create an entry for the readable-recordings directory for SAMBA and one for NFS.  **Note if you are going to NFS share with a OS X box you will need to edit the /etc/exports file to include the insecure option.

    Restart Samba:

    prompt$ sudo /etc/init.d/samba restart

    Restart NFS

    prompt$ sudo /etc/init.d/nfs-kernel-server restart

    You should now be able to mount the shared file system from the network


    With Leopard Apple introduced its version of backup software for the Mac called Time Machine along with some hardware called Time capsule.  Adorned with coverflow as an interface it is simple to use and configure.  Periodic backups are displayed through a coverflow interface which allows users to go backwards in time to any point they desire.  Simply attach a usb drive to the local machine and Time machine does the rest.  By default it is not meant to be used with a Network Attached Server (NAS) server (other than Apple Time capsule).  However, it can certainly be done.

    A Little background to the Time Machine process.

    What time machine does is creates a disk image (sparsebundle) on the usb drive which is initially set at a small size than is allowed to grow until it reaches a size below the remaining disk space on the drive.  Only one image can reside on a given disk partition. For a one mac configuration this is not a problem.  However in a multiple mac environment this is not practical.  In this type of environment a NAS server is best suited.  For a one partition NAS setup see basic setup. For a multiple mac backup setup see Advance section

    Getting Time Machine to work on a FreeNAS server (BASIC SETUP)

    1. Build a sparsebundle.  In terminal Type the following. Filling in the parameters for size $MACHINENAME_MAC_ADDRESS.  Where $MACHINENAME is the name give in Network preferences and MAC_ADDRESS is the mac address of your ethernet port.

    tom$ hdiutil create -size $SIZEg -fs HFS+J -type SPARSEBUNDLE -volname “Backup of $MACHINENAME” $MACHINENAME_$MACADDRESS.sparsebundle

    for example:

    tom$ hdiutil create -size 70g -fs HFS+J -type SPARSEBUNDLE -volname “Developer” Developer_001a629dd5c3.sparsebundle

    Then move the newly created sparse bundle to the NAS Drive
    2.  Open a terminal session and type the following to allow time machine to use the NAS

    Terminal Time Machine NAS

    3.  Open Time Machine application and select change disk.  You should see the NAS drive as an option.

    Getting Time Machine to work on a FreeNAS server (ADVANCED SETUP)

    !!!!!!!!! Warning proceeding past this point will destroy all data on the drive !!!!!!!!!!!!!!

    1.  FreeNAS does not support disk partitioning.  To do this you have to use a Partitioning application such as SuperFdisk.  It comes as a iso image that can be burned to cd.

    2. Once SuperFdisk is burned to cd boot the NAS into it.

    3.  Selecting the Hardisk should show the partitions already on the drive.

    4.  Erase the Master Boot Record and create the new partitions.

    Each new partition will be a primary partition for which there can be a maximum of 4. So if you have 3 Macs running time machine you will need a minimum of 3 partitions

    5.  Once finished reboot into the FreeNAS and proceed to the FreeNAS web interface and configure FreeNAS to setup and format the new partitions.  Once in the Web interface go to Disk then Mount Point.  Click on the plus sign to add a mount point.  The mount point will refer to one of the partitions in on the disk.  The add mount point window will display.  Select the Disk then go to the Partition and select 1 from the pull down menu for partition 1.  Select the File system for the partition to be formated in  (ufs is preferred).  Give it a share name and a description.  Then click add.  Repeat for additional partitions.

    6.  Now that the partitions are complete. Go to the Basic setup above and create a sparsebundle for each Mac, copying them into there respective partitions that were just created.