HowTo: Disappearing NSTable Buttons

Posted: August 10th, 2010 | Author: Remi | Filed under: Cocoa, OS X, Programming | No Comments »
Disappearing NSTable Buttons

Completed Project

Recently I was working on a project where I wanted a certain effect. This was that I wanted the user to be able to delete items out of a table by clicking on the item and not having to add some button somewhere else to do it. So the answer was to put a button on the table to delete it. That was simple enough, just make a table with button cells, but it didn’t look very nice, it showed all the button when you could only delete one at a time. So thus, I decided to make the buttons only appear on the selected table items. Its simple, functional, and you can do it too if you just follow this short guide.

To tackle this problem, there are two “hacks” that we need to do.  First, we have to somehow make the NSButtonCell hide itself.  Next, we have to keep track of which row is selected, and tie that information back to our buttons. To accomplish the first task, will tie the button being hidden to it’s enabled value, since this way is easier then creating a new binding, and it doesn’t matter is the button is disabled if it’s hidden anyway.  Subclass NSButtonCell and override this method with this code.

- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
	if([self isEnabled])
		[super drawWithFrame:cellFrame inView:controlView];
}

In interface builder, drag a NSButtonCell to one of the columns of your NSTableView. (Apple hides it as a ‘Check Box Cell’, see below, you have to change the type to ‘Momentary Push In’).

Interface Builder Check Box Cell (NSButonCell)

Check Box Cell (NSButtonCell)

Setting the Class to HidingButtonCell

Setting the Class to HidingButtonCell

Change the class to your custom subclass. Next we need to somehow get the data in a form we can bind to the button’s enabled key.  There are potentially a couple ways to do this, but I decided to subclass NSTableView, and override this method.

- (void)selectRowIndexes:(NSIndexSet *)indexes byExtendingSelection:(BOOL)extend
{
	[super selectRowIndexes:indexes byExtendingSelection:extend];
	[controller setSelectionIndex:[indexes firstIndex]];
 
	int i;
	for(i = 0; i < [[controller arrangedObjects] count]; i++)
	{
		[[[controller arrangedObjects] objectAtIndex:i] setObject:
			[NSNumber numberWithInt:[indexes firstIndex] == i] forKey:@"enabled"];
	}
 
}

Of, course this way of doing this assumes you’re binding to an NSArray of NSMutableDictionaries.  Next, back in Interface Builder we can bind the column to the new data that’s going to be generated with that method. And thats it enjoy you’re disappearing buttons.  If you want the button to delete the row, like mine, just connect the NSButtonCell’s action to the NSArrayController’s remove: method. If I made any mistakes, or made anything unclear, please leave a comment.  For a closer look, Download the Xcode Project


New From Kunugiken WikiTyper

Posted: May 15th, 2010 | Author: Remi | Filed under: Cocoa, OS X, Programming | No Comments »

I was playing the fabulous typing game TypeRacer when I thought that it would be fun to type some sort of other text. I decided to try making my own typing program. So I threw together this new typing game for OS X that lets you type random paragraphs of text from wikipedia. Its absolutely free, try downloading it here Download Page.

WikiTyper in Action

If you have any comments on the game please post them below. Some things I know are not working and I might fix in the future if people ask about them.  The words per minute is actual words per minute not the correct wpm, (if anyone knows the formula?)  Also occasionally it will display characters that you cannot type, but I couldn’t find a way to remedy that efficiently.  Finally, for those of you Linux and Windows users, a Java port is being made by someone else.  I will post a link if/when it is finished.


Fixing Old Printer Drivers to Work in Snow Leopard

Posted: September 3rd, 2009 | Author: Remi | Filed under: OS X, Personal | 17 Comments »

The upgrade to snow leopard may be leaving some of you with not working printers. When I upgraded I could no longer print to my Xerox Workcentre Pro 238. The thing it seems is that snow leopard deletes all of your old PPDs and printer drivers. I had to download and install the driver again. Then alas, after doing so, the printer failed to function, it gave me the error message “The printer software was installed incorrectly. Please reinstall the printer’s software or contact the manufacturer for assistance.”

After researching the error, I came to the conclusion that it has to do with snow leopard upgrading CUPS. The newest version of CUPS, I read, requires that all the drivers’ files be owned by root. After investigating I found that Xerox’s PPD’s and plugins were NOT owned by root and thus causing the problem. To remedy this problem just type this command into the terminal:

sudo chown -R root:admin /Library/Printers

(The command might take a while to run.) This owns the /Library/Printers folder and everything in it to root, this could potentially fix many different printer software to work with snow leopard since it can effect pretty much any printer driver. So if you’re having problems try giving this a shot. Good luck.


Snow Leopard and Close to Instant Gmail Contact Sync

Posted: August 31st, 2009 | Author: Remi | Filed under: Cocoa, OS X, iPhone | 1 Comment »

I’m sure many of you are aware that Apple has just released their newest OS X update called Snow Leopard, I was lucky enough to get my hands on a copy already. One very interesting feature of this update is the support for syncing your contacts in Address Book.app with Gmail’s contacts. Through Gmail, you can already sync your contacts to your iPhone thanks to Google Sync‘s MS Exchange servers. With the these two services combined you can have your contacts on your phone synced to your computer and vice-versa fairly instantly without MobileMe. The problem I was having was that this service didn’t do quite instant enough for my taste, here’s how you enable the sync, and how you can tweak it to make it even closer to instant.

First enable Gmail Contacts sync in Address Book by clicking Address Book > Preferences… > Accounts. Then click “On My Mac”, and then check the box next to synchronize with Google. Enabling Google Sync in Address Book in Snow Leopard After enabling it you will be prompted for your Gmail username and password. Then you should see a sync icon in your status bar. This lets you manually force a sync with google by clicking “sync now.” When it syncs you will probably have to resolve some ‘sync issues’ (basically deciding which contact is correct, the Gmail or Address Book version.)
Snow Leopard Sync Menu
If this icon annoys you, just hold down the apple key and drag it out of the bar to remove it, to put it back you can enable it in iSync.app’s preferences.

Now to tweak it. Your computer syncs your contacts in a job in that runs through a process called launchd (For those of you that don’t know, in Tiger and newer, launchd takes the job of cron on normal unix systems.) By default this process runs only once every hour, we are going to try and tweak this. To easily edit your loaded jobs, download Lingon from here http://sourceforge.net/projects/lingon/files/. Open up Lingon, on the left under ‘My Agents’ you should see ‘com.google.GoogleContactSyncAgent.’ Click this, and you here you are able to change it from running every hour to as little time as every second (although I don’t recommend this AT ALL.) Just adjust this setting to a shorter time period to speed it up. The real trick here though is that you can set something called a watch file/directory. This lets the process run when that file/directory has been modified. To make the sync run whenever you change one of your contacts you should just fill in under “Run when this file is modified” this file /Users/remi/Library/Application Support/AddressBook/AddressBook-v22.abcddb This file is your address book database, so hence it runs when you update the database. Lingon Editing Snow Leopard Google Sync Agent Remember that this makes your contacts instantly updated from your computer to google, but no the other way around. The frequency that the contacts come into your computer from google is determined by the “run it every” setting. I do not know why apple did not have the file set to watch the address book database to begin with, so I’m not sure if there are any adverse effects, but there has been none that I have experienced so far. Once you are finished editing the job, hit save, then log out and back in or restart for it to take effect. To try it out just edit one of your contacts in Address Book.app and see the update automatically appear on Gmail, and if you iPhone is synced to Gmail, then right to your iPhone.

Please post a comment if you have problems with this method, good luck everyone!


Sending Growl Notifications from Ubuntu

Posted: June 29th, 2009 | Author: Remi | Filed under: OS X, Ubuntu | 8 Comments »

If you’re like me then you love being up to date on things happening on your network.  So when things were happening on my Ubuntu server I wanted to be alerted in some way.  I tried to use email but that was just impractical.  Then I came up with the idea to use growl.  If you don’t know, Growl is a messaging system for OS X that many applications use to notify the user with pleasant on screen notifications.  I remembered that growl would accept on notifications received over the network so I went out to the internet to find a way to send these notifications from Ubuntu.  I found a wonderful utility for doing it using python, which is a scripting language that comes pre-installed on Ubuntu. The name is pygNotify.  This would have been all fine and well and I would have had handy growl alerts form my server, but as it turned out there was very little documentation out there as to how to get this setup, and the included instructions are overly-simplified.  Therefore, I am writing this.

On the Ubuntu computer open the terminal, found in Applications > Accessories > Terminal.  First we’re going to create a folder to keep this growl stuff in.

mkdir ~/growl
cd ~/growl

of course you don’t have to keep it in your home directory
Next, lets download pygNotify

wget http://pygnotify.googlecode.com/files/pygNotify-0.1.tgz
tar xvfz pygNotify-0.1.tgz
mv pygNotify-0.1/pygNotify.py .
rm -r pygNotify-0.1

The next thing you need is get the python libraries from the growl SDK, that you can download from their website here http://growl.info/source.php Unfortunately the SDK is in a dmg so you’ll have to use a mac to extract it then copy it to the Ubuntu machine. You’ll need the folder Bindings/Python and also the script Bindings/Network/netgrowl.py. I will write the rest assuming you copied them into a folder called dmg in your home directory. Now we need to install the libraries. Cd into the directory you copied over from the dmg.

cd ~/dmg/Python
sudo python setup.py install

Now you need to move the netgrowl.py also from the dmg to the growl folder we created earlier

mv ~/dmg/netgrowl.py ~/growl

Then we should be done with the stuff from the dmg so we can clean up

rm -r ~/dmg

It should be all installed at this point. Now we need to enable receiving network notifications on the mac computers you want to receive the notifications from your ubuntu machine.

If you haven’t already, download and install growl from its website http://growl.info/ Once installed, go to System Preferences in the apple menu and click on Growl. Then click the network tab, then check “Listen for incoming notifications” and also check “Allow remote application registration” and set a password. Even if you don’t want a password, as far as I can tell you have to set one for it to work. Next you’ll need your computer’s ip address. Open Terminal.app found in /Applications/Utilities and type

ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2

The output should be your ip, write it down because we’ll use it in this next step.  Repeat for each mac.  Now back on your ubuntu machine we need to register your server as an application that can send notifications on your mac.

cd ~/growl
python pygNotify.py -n "Ubuntu Server" -p "password" -H your.macs.ip.address -r -m "register"

Please note that the second command is one line.  Replace password with the password you set earlier, and replace the part after -H with your mac ip address.  You’ll have to do this for every mac you setup to receive network notifications.

Note that the option after -n is the title of the application as it will appear to growl, and you can register multiple times with your mac if you use different names. By using different names for different sets of notifications it becomes possible to set customized settings for both on your mac. ie you could register “System Monitor” and maybe “Email Server” and have them have different message styles on the mac

Once the command runs, it should be registered on the mac and show up in the application list. A keychain confirmation may come up on the mac asking you if you want growlHelper to access the keychain. You should hit always allow, so this notification doesn’t come up every time.

Note: If when you run the command you get a “IndentationError: expected an indented block” when you try to run the script, my best guess is that its due to the formatting being messed up when you copied it to the server. If you find yourself unable to fix this just copy and paste the file from here: http://the.taoofmac.com/space/Projects/netgrowl and finally that worked for me.

Now to send a message

python pygNotify.py -n "Ubuntu Server" -t "test message" -p "password" -H your.macs.ip.address -m "hello world"

Again note that the command is one line.  The part after the -t option is the title of the alert, and the part after -m is the message. Also note if you want the alert to be sticky, meaning it stays on the screen, you can use the -s option.

And that’s, it hopefully. If you have problems with it registering or sending messages, be sure to check your firewall settings, to make sure growlHelper.app can access the internet, or that udp port 9887 is open I believe. Also you can try deleting the password set by growl in the keychain, and resetting it in the System Preferences Growl pane again. This can reset growl’s privileges to access the keychain, which may or may not be set to deny it access. The whole setup can be a finicky system at times, so good luck!


My Top 5 Most Awesome Free Apps for OS X!

Posted: January 4th, 2009 | Author: Remi | Filed under: OS X | 2 Comments »

As you might have guessed I quite love macintoshes, and thus I feel compelled to tell the world about some of my favorite free software for OS X!

# 5  Cyberduck

A truly great ftp client, with excellent features like bonjour, growl, and quick look support.  As far as I’m concerned, this is the only FTP client you will ever need for OS X.  It has mostly all the good features of programs like transmit.  With great reliability and nice interface, it is a download you can’t miss.  The only complaint I have is that webDAV support isn’t great.  Visit Site

#4 The Unarchiver

This is an amazing program that brings support to OS X for extracting an amazing amount of archives, even archives made on machines from other countries.  The icing on the cake is that it has almost no presence and blends with the OS X gui perfectly, practically replacing the default unarchiving program in OS X.  This program is a must download and is definitely worthy of the “the” at the beginning of its name.  Forget Stuffit, this is the only unarchiving program you’ll need. Visit Site

VLC#3 VLC

A must for any operating system.  VLC can play virtually any video or  music file right out of the box! (or disk image rather).  But the amazing video bliss doesn’t stop there, it can even re-encode the video and save it back to disk.  It can even capture video from your camera or your screen.  This is an amazing application that follows the mac ideals of “just working.” Visit Site

#2 Adium

This instant messenger is a great choice for any multi-protocol user on OS X.  It supports an amazing amount of protocols including MSN, AIM, Google Talk, Bonjour, and the new Facebook chat protocol.  If that wasn’t enough, it has growl support, custom themes, scripting support, and tons of plugins and extras.  The only downside is that it does not have video or audio support, but it is supposedly going to take advantage of leopard’s new video features for the 2.0 release. Visit Site

#1 Smultron

I use this application all the time.  It is close to an equivalent to textmate, but with not quite the same features.  In my opinion, smultron gives a better range of features and has a great reliability, and impressive usability.  I use this for writing HTML, Javascript, PHP, and any other scripting languages.  It can open any file as plain text, which is something you may take for granite if you are new to OS X.  This gets my number one spot basically because of the essentialness of this program to my OS X experience, and because it never fails to surprise me with helpful features. Visit Site