Debugging Javascript in Safari

When I need this, I use it every day, 38 times a day, for a week. Then I forget about it. No more.

For quick-n-dirty Safari Javascript debugging, try “window.console.log()”.

Hidden tricks in the Xcode editor

I’m quite fond of Xcode’s built-in editor. I have no problem with anyone trying to write the Next Great Programmer’s Editor, but the bar is pretty high. I use Xcode for almost all of my programming, including web sites and Perl.

In C, you can use the #pragma mark directive to add a comment to the function listing at the top of the window. In Perl, you can do the same with “TODO:” comments. However, I wanted to see if I could add a mark without having to use “TODO:”. I dug around and found the XcodeEdit private framework and discovered the syntax files for the Xcode editor. Here is the full list of marker codes:

  • TODO:
  • FIXME:
  • !!!:
  • ???:
  • MARK: This one is special. You don’t get the mark, just the text!

Back to work!

Xcode project and file templates

I’ve known about Xcode project templates for quite a while. I even wrote a little script once that would take an Xcode project and convert it into a template. All you had to do then was copy it to a magical place in your home directory and you had custom Xcode projects.

Unfortunately, there was no way to setup file templates. If you went to Xcode File -> New File, you would get the Xcode default files.

As of Xcode 3.1.2, there are improvements. You can now specify both project and file templates. Go to /Library/Application Support/Developer/Shared/Xcode. You can create Project Templates and a File Templates directories. Copy your favorite default set from /Developer/Library/Xcode/ and edit the files. Now, just like in New Project, there will be a set of User Templates in the New File dialog box in Xcode. Of course, none of this is documented.

Don’t forget to store your templates somewhere in your home directory and use symbolic links in the system directory. That will help with upgrading.

Thanks to the MacFUSE project for tipping me off.

Paths in MacOS X

A while back, I installed git to download some random open-source code that I’ve since forgotten about. I noticed this when hacking on my .bash_profile paths to add ImageMagick. I saw that git had been inserted into my path and I couldn’t figure out how. I thought they had been screwing around with my system bash scripts but no – something else was going on…

It seems MacOS X has a little known improvement to UNIX life on the desktop. Instead of adding paths login scripts, you can put them in the /etc/paths.d directory. Add a unique text file whose contents are the path to add. You don’t get control over the order of loading, but that (usually) shouldn’t be a big deal. There is also a /etc/manpaths.d as well.

I normally don’t like to put third party stuff in / directories. That is where things get lost when upgrading. I don’t know if I should use this or not, but I don’t want to forget about it.

MacOS X Application initialization and shutdown sequence

Perhaps this is it?

  1. main.m calls the NSApplicationMain function.
  2. init methods of classes in the main nib file
  3. awakeFromNib called on classes instantiated by the nib
  4. [NSApp run]
  5. [NSApp finishLaunching]
  6. Any windows in the nib that were marked as ‘visible at launch time’ are put on screen about now.
  7. applicationWillFinishLaunching:
  8. application:openFile:
  9. applicationDidFinishLaunching:
  10. <run main loop>
  11. applicationShouldTerminate:
  12. reviewUnsavedDocumentsWithAlertTitle:cancellable:delegate:didReviewAllSelector:contextInfo:
  13. closeAllDocumentsWithDelegate:didCloseAllSelector:contextInfo:
  14. <didReviewAllSelector>
  15. applicationWillTerminate:

Updated to add information from this post.

Custom Perl modules

I may need a Perl category here shortly.

Once again, I have had to re-find the following information about doing custom installations of CPAN modules. Here are the details…

$ PERL5LIB=$HOME/lib/perl5/5.8.7:$HOME/lib/perl5/site_perl/5.8.7

$ perl Makefile.PL PREFIX=~/lib

$ make
$ make install

Going where you want

I know this blog is supposed to be about programming. But we programmers sometimes like to squirrel away files in odd places. The standard MacOS X file open dialog doesn’t let you get to those places. Or does it?

I remember long ago finding a keyboard shortcut that would pop up a little window in a file open dialog that would let you type in a path for a directory. Somehow, I managed to find it again. This time, I shan’t forget it.

The keyboard shortcut is Shift-⌘-G

Carbon to the rescue

There are some areas of MacOS X where Cocoa just doesn’t do it. Either the Cocoa version doesn’t have all the options you need or Cocoa just doesn’t have the function. In many cases, Apple has quietly updated some ancient MacOS Toolbox function to work in MacOS X. Here are a few of these:

FSFindFolder and FindFolder – Helps you find all those “special” directories.
All of Navigation Services – For when NSOpenPanel just doesn’t cut it.