Archive for May, 2007

Introducing Polish: A new framework

A month ago, Paul Kim over at Noodlesoft made a post about a proposal for a new way to install. In it, he described how it might be advantageous to display a dialog to the user asking them if they’d like to install the application if it were running from a disk image (or some other unwritable media).

As it so happens, I had already intended to write some code that checked that very thing, to fix a problem with Picture Switcher. I hesitate to call it a bug — it’s more like an unintended side effect. The problem was that in my last version, I decided to add in a dialog asking the user if they would like PS to run when they logged in. All fairly standard. What I hadn’t taken into account (and this would be a bug), was users running PS from the disk image. I should have put in a check for that. The unintended side effect is that, after having said yes to that dialog, every time they logged in the disk image would be mounted and run PS from there. I hadn’t even known the login items would do such a thing. Suffice to say, I’ve gotten some support emails about this issue.

So, I needed to write some code to both check if PS was running from a disk image and some code to fix the login item problem. I was working on another portion of PS when Paul made his proposal, but this past week I came back to fix up that section. The end result: a new framework.

Polish handles this and also handles login items. It will check if you are running from unwritable media OR running from the user’s download folder (for those of you using zip files or internet-enabled disk images), and if it is, will display a dialog asking the user if they’d like to copy the application to a different location. Polish can also check to see if the application is a login item, and if not display a dialog asking the user if they’d like it to run when they log in. You don’t have to check for either — you can check for whichever one suits your needs.

I wrote up my own code based loosely on the LoginItemsAE code for Polish, using NSAppleEventDescriptor (mostly — there are a few lower level AE calls that are still present). It does work. You can use Polish for the preferences section of your application, if you allow the user to add/remove it from the login items list. You’re not limited to just the check.

Here is the dialog presented to the user if they are running from some unwritable media or running from their download folder:
Polish's copy dialog

Note that I decided to use the term ‘copy’ rather than ‘install’ — I felt that had less of a psychological factor attached to it. ‘Install’ implies that more than just the application may be copied to the hard drive.

Here is the dialog presented to the user when asked if they’d like the application to run when they login:
Polish's login item dialog

The images are taken from the test application that comes with the framework. “Polish Test” will, of course, be replaced by your application’s name.

I can hear a few of you now: “Oh no, those dialogs are terrible! That won’t go with my application…” Well I actually thought of that. If you are using some sort of custom window scheme, or just don’t like they way the dialogs look, you can customize them or entirely replace them with your own window.

The download for the Polish framework contains a built version of the framework, a test application, the source to both of those, and documentation.

Head on over my Developer page to download it. The reference is also available there online, if you wish to look through it before downloading Polish.

For anyone curious as to why I named the framework “Polish” — well, I think the framework adds some polish to an application. But also, the Sparkle framework had a little influence, as well. ;)

Updated & New Code

For all of you developers who are using my code (all 3 of you), I’ve updated my DSClickableURLTextField and DSGeneralOutlineView classes, and added a new class, DSGeneralTableView. I’ve also written up some class references for these classes, so things are a little more documented now.

Jens Miltner emailed me some fixes to some subtle bugs with DSClickableURLTextField, and I added some functionality. Here’s the change list for it:

    Changes by Jens Miltner:

  • Fixed a problem with the text storage and the text field’s attributed string value having different lengths, causing range exceptions.
  • Added a delegate method allowing custom handling of URLs.
  • Tracks initially clicked URL at -mouseDown: to avoid situations where dragging would end up in a different URL at -mouseUp:, opening that URL. This includes situations where the user clicks on an empty area of the text field, drags the mouse, and ends up on top of a link, which would then erroneously open that link.
  • Fixed to allow string links to work as well as URL links.
    Changes by me:

  • Overrode -initWithCoder:, -initWithFrame:, and -awakeFromNib to explicitly set the text field to non-editable and non-selectable. Now you don’t need to remember to set this up, and the class will work correctly regardless.
  • Added in the ability for the user to copy URLs to the clipboard. Note that this is off by default.
  • Some code clean up.

I cleaned up the code a bit in DSGeneralOutlineView, and also added a new delegate method. Also of note, I added a parameter to the delegate method allowing you to create a custom drag image. If anyone is using this with DSGeneralOutlineView, you’ll need to update the delegate method to include the new parameter.

Here’s the change list for it:

  • Cleaned up the code a bit.
  • Added a new parameter to the delegate method that lets you create a custom drag image.
  • Added a new delegate method that will inform you of a failed drag.

DSGeneralTableView is a NSTableView subclass to go along with my DSGeneralOutlineView class. The two classes are almost identical, with the exception being one delegate method which calls with a row number for DSGeneralTableView rather than with an item with DSGeneralOutlineView.

The class references I wrote up are included in the download file for the respective classes, and are also available for viewing online:

DSClickableURLTextField Class Reference
DSGeneralOutlineView Class Reference
DSGeneralTableView Class Reference

Hope y’all enjoy the updates, and happy coding. :)

Yes, I’m still alive

Hey all, sorry for the lack of posts. I hadn’t intended to go two months without posting. I suppose this makes it more of a rocky start than a bumpy one.

I thought I’d give a status update on where I am with things:

An update to Picture Switcher is about 88% done.
An update to Web Control is about 60% done.
An update to Desktop Log is about 40% done.
An update to Pref Setter is about 10% done.

As you may guess from the above, I’m spending most of my time with Picture Switcher. It’s keeping me rather busy, which has contributed to the lack of posts (though I’ll be honest and say not totally).

If it helps any, my friends are all wondering where I’ve disappeared to as well. ;)