Deprecated: Function split() is deprecated in /mnt/home/cn/cn-web/songshu/lib/pages/DisplayBlogArticleList.php on line 36
Articles matching: osx
ChipmunkNinja
Ninjas are deadly. Chipmunk Ninjas are just weird.
About this blog
Marc Travels
Marc on Twitter
JustLooking on Twitter

Marc Wandschneider is a professional software developer with well over fifteen years of industry experience (yes, he really is that old). He travels the globe working on interesting projects and gives talks at conferences and trade shows whenever possible.

My Publications:

My book, "Core Web Application Programming with PHP and MySQL" is now available everywhere, including Amazon.com

My "PHP and MySQL LiveLessons" DVD Series has just been published by Prentice-Hall, and can be purchased on Amazon, through Informit, or Safari


ABCHKMPRaRoSTVW
xxxxx-xxxxxxxxx

Popular Articles:


Top Tags:


Recent Comments:

cncool wrote:

GLint zeroOpacity = 0;
[[self openGLContext] setValues:&zeroOpacity forParameter:NSOpenGLCPS...
Posted to: Things I've learned about CoreImage (and Quartz, and OpenGL) in two weeks
Jun 03, 2008 | 21:34:13
1080p MKV playback on Mac OS X (VLC)
By marcwan

If you’re like me, you used to think that your Intel Mac was a pretty powerful computer. With all of those super zippy cores and RAMs and caches and all that, everything does seem to go a lot faster on the newer machines. My JustLooking compiles went from nearly 4 minutes on my PowerBook G4 to about 35 seconds on my 2.33GHz laptop.

But then came all those 1080p MKV files, with their unbelievable (basically unwatchable) jerkiness, and you found yourself questioning the new religious order. Is the machine, perhaps, actually a piece of junk? Was it that hard disk upgrade you did? The new RAM you installed? Leopard? Some awful combination thereof?

[Read Rest of Article]
Jan 08, 2008 | 21:36:33
Announcing TunnelerX 0.9.5 - An SSH Tunnel for your Mac OS X menu bar
By marcwan

TunnelerX is an application for Mac OS X to let you run a single SSH tunnel from your system menu bar, typically to securely re-route HTTP (web browsing) traffic to a remote proxy server. If you have ever had to run one of the following commands in a little Terminal window in the corner of your screen, then this application is for you:

ssh -N -L 8123:localhost:8123 bobo@theclown.com
ssh -N -D 8123:localhost bobo@theclown.com

Changes for 0.9.5:

  • The application is now named TunnelerX instead of Tunneler
  • A few bugs have been fixed related to sleeping and waking up the computer
  • New graphics and icons for the application. It’s a bit less ghetto looking now.

For the 1.0 release (upcoming), I will add Growl notifications for those who wish them. The Growl website is currently down, so I can’t do much yet.

Downloading

[Read Rest of Article]
Nov 20, 2007 | 21:23:17
Announcing Tunneler 0.9 - An SSH Tunnel for your Mac OS X menu bar
By marcwan

Tunneler is an application for Mac OS X to let you run a single SSH tunnel from your system menu bar, typically to securely re-route HTTP (web browsing) traffic to a remote proxy server. If you have ever had to run one of the following commands in a little Terminal window in the corner of your screen, then this application is for you:

ssh -N -L 8123:localhost:8123 bobo@theclown.com
ssh -N -D 8123:localhost bobo@theclown.com

Downloading

[Read Rest of Article]
Jun 29, 2007 | 20:50:34
Things I've learned about CoreImage (and Quartz, and OpenGL) in two weeks
By marcwan

I recently spent two weeks converting JustLooking, my Mac OS X Image Viewing program, from NSImage to CoreImage and friends. This experience was overall much easier than I expected, and I have learned a bunch of things, some of which might have been handy to have known in advance.

The good news is that it mostly lives up to the hype. The bad news is that it’s not without tricks and traps of its own. Here are some notes and comments.

[Read Rest of Article]
Mar 08, 2007 | 20:07:45
Weird Cocoa Errors 101
By marcwan

The other day, I was working on JustLooking, changing the appearance and the like of a couple of dialogs. As I ran the programs and went to show the dialogs (“panels” in the local terminology), nothing would show and I’d get an error in my XCode results window:

"Unknown class 'CustomCombo' in nib file. using 'NSObject' instead."

I spent the next half hour trying to figure out why Interface Builder didn’t know about this class: it was there in the class inspector, and the ui widgets were correctly set up to use that new class, and all the hookups in the UI also seemed correct.

Well, I finally figured out: when I first developed the class, I had some errors in it, but wanted to test a few things out in my program elsewhere. So I had unchecked it in XCode, telling the IDE not to compile and link it.

Thus, when Cocoa tried to load the NIB file, it couldn’t find the definition for the class, and just put in NSObject instead.

Here’s to hoping that this blog entry saves somebody that 30 minutes I spent on that one.

[Read Rest of Article]
Mar 03, 2007 | 22:26:50
JustLooking 2.0 Preview!
By marcwan

So, after a month or so of active development, I’m almost ready with version 2.0 of JustLooking. I’m just waiting for some localisation help, and then I’ll go ahead with the release. The first releases were quite functional, but pretty ugly, I think. A few users from the internet made some suggestions on how to improve the UI and I have completely redesigned it.

Click for larger version

In addition to a complete update to the user interface, I have added the following new features to version 2.0:

  • Saving of rotated images (JPEGs, GIFs, PNGs, BMPs, and TIFFs)
  • Remote Control Support in slide show mode.
  • Image displaying and resizing is muuuuucchhh faster now.
  • Hold down the ‘OPTION’ key on startup goes to full screen slide show.
  • many bug fixes in the code, including some animated GIF problems.

I will spend the next week or so fixing the last couple of bugs in the program and waiting for the last bits of localisation help to come in, and will then release it both on this server and on the BitTorrent networks.

Please feel free to send me your requests for future versions or reports of any bugs or problems you find in the program. I’m thinking the next big features will lie in image resizing and saving of images in different formats.

[Read Rest of Article]
Jan 02, 2007 | 05:12:49
Taking the Fun out of Buying a new Computer
By marcwan

In normal times, buying a new computer is a rather fun experience. In addition to the endorphin rush caused by plonking down a huge wad of cash for such a small – but often 好看 (that’s Chinese for good looking) – piece of hardware, you get to take it home and play with it and discover all the new and fun things that are different about the new toy. Even if it’s still running Microsoft Windows, your new vendor has probably come up with some new set of stuff to include with the machine. Or, far more common with me, my last attempt to finally come up with the “ultimate organisation of my hard disk™” was a miserable failure, and I’m excited about trying out something new.

So, imagine my disappointment when I recently upgraded my 15” Powerbook G4 to a shiny new 15” Macbook Pro.

[Read Rest of Article]
Oct 26, 2006 | 07:15:59
Cocoa Programming: How to fetch Paper Names, Localised Names, and Page Sizes for a Printer
By marcwan

For a recent project written in Cocoa for Mac OS X, I found myself wanting to get the following set of information for a particular printer:

  • A list of all available paper types
  • Printable names for these paper types
  • Page Sizes
  • Imageable Margins for those same pages.

It turns out that there is no way to get this in Cocoa, and actually it’s not all that easy to find this information in Carbon either.

So, after some research and investimigation on the Intarwebs, as well as much combing through the various PM* header files (buried so deep in a directory on my machine that I had to save the directory name somewhere so I’d be able to find them again!), I’ve come up with the following method to do all the above.

CUTOFF
It returns an NSArray. Each paper type supported by the printer gets one item in the array, which is an NSDictionary set-up to use key/value pairs. There are the following pairs:

  • PAPER_NAME (NSString): The system name for the paper.
  • LOCALISED_PAPER_NAME (NSString): The display name for the paper.
  • PAPER_SIZE (NSValue): The size of the paper in 72dpi User Space Units. Use [NSValue -sizeValue] to get the actual value.
  • PAPER_IMAGEABLE_MARGINS (NSValue): The imageable bounds of the paper in 72dpi User Space Units. Use [NSValue -rectValue] to get the actual value.

I’ve noticed that there are some issues with memory allocation in the following code: If I run it a few hundred thousand times, I start to see some memory leaks, which is most upsetting. Given that I can’t free anything else in this code without crashing it, I worry that it might be a system leak. However, given how rarely this code is ever executed (maaaaayyybe 5-10x per process lifetime in an extremely print happy case), It’s something that can be investigated later.

Here be the code, laddies:


+ (NSArray *)paperSizesAndNamesForPrinter: (NSString *)printerName
{
    PMPrintSession printSession = NULL;
    CFArrayRef printerList = NULL;
    PMPrinter thisPrinter = NULL;
    int numPrinters;
    OSStatus err;
    int i;

    err = PMCreateSession(&printSession);
    if (err != noErr)
        [JLUnknownPrinterErrorException generate];

    @try
    {
        /**
         * Get a list of all printers.
         */
        err = PMServerCreatePrinterList(kPMServerLocal, &printerList);
        if (err != noErr)
            [JLUnknownPrinterErrorException generate];

        /**
         * Now, loop through them until we find the printer we're looking
         * for.  Then we can get the properties.  We throw if the printer
         * isn't found.
         */
        numPrinters = CFArrayGetCount(printerList);
        for (i = 0; i < numPrinters; i++)
        {
            CFStringRef thisPrinterName;
            thisPrinter = (PMPrinter)CFArrayGetValueAtIndex(printerList, i);

            thisPrinterName = PMPrinterGetName(thisPrinter);
            if ([(NSString *)thisPrinterName caseInsensitiveCompare: printerName] == NSOrderedSame)
            {
                CFRelease(thisPrinterName);
                return [NSPrinter extractInfoFromPrinter: thisPrinter];
            }

            CFRelease(thisPrinterName);
            thisPrinter = NULL;
        }
    }
    @finally
    {
        /**
         * Clean up.  Exceptions will still throw back up the stack.
         */
        if (printerList != NULL) CFRelease(printerList);
        PMRelease(printSession);
    }

    return nil;
 }

+ (NSArray *)extractInfoFromPrinter: (PMPrinter)printerInfo
{
    NSMutableArray *outputArray = [NSMutableArray arrayWithCapacity: 10];
    CFStringRef paperName = NULL, localised = NULL;
    NSMutableDictionary *paperProps;
    CFArrayRef paperList;
    PMPaper thisPaper;
    int j, numPapers;
    OSStatus err;

    /**
     * First, get a list of the paper sizes and create an NSArray 
     * for them all.
     */
    err = PMPrinterGetPaperList(printerInfo, &paperList);
    if (err != noErr)
        [JLUnknownPrinterErrorException generate];

    @try
    {
        numPapers = CFArrayGetCount(paperList);
        for (j = 0; j < numPapers; j++)
        {
            NSValue *imageableMargins, *paperSize;
            double paperHeight, paperWidth;
            NSRect adjustedMargins;
            PMPaperMargins margie;

            thisPaper =  (PMPaper)CFArrayGetValueAtIndex(paperList, j);

            /**
             * Get the system non-localised paper name.
             */
            PMPaperGetID(thisPaper, &paperName);


            /**
             * Get the localised paper name.
             */
            err = PMPaperGetName(thisPaper, &localised);
            if (err != noErr)
                [JLUnknownPrinterErrorException generate];

            /**
             * Finally, build up the size.
             */
            err = PMPaperGetHeight(thisPaper, &paperHeight);
            if (err != noErr)
                [JLUnknownPrinterErrorException generate];
                    
            err = PMPaperGetWidth(thisPaper, &paperWidth);
            if (err != noErr)
                [JLUnknownPrinterErrorException generate];

            paperSize = [NSValue valueWithSize: NSMakeSize(paperWidth, paperHeight)];

            /**
             * This gets the imageable margins for the page type, which
             * is very useful.
             */
            PMPaperGetMargins(thisPaper, &margie);
            adjustedMargins = NSMakeRect(margie.left, margie.top,
                                         (paperWidth - margie.left - margie.right),
                                         (paperHeight - margie.top - margie.bottom));
            imageableMargins = [NSValue valueWithRect: adjustedMargins];

            /**
             * Finally, create a dictionary with these values and then add
             * them to da array.
             */
            paperProps = [NSMutableDictionary dictionaryWithCapacity: 3];
            [paperProps setValue: [NSString stringWithString: (NSString *)paperName]
                        forKey: PAPER_NAME];
            [paperProps setValue: [NSString stringWithString: (NSString *)localised]
                        forKey: LOCALISED_PAPER_NAME];
            [paperProps setValue: paperSize forKey: PAPER_SIZE];
            [paperProps setValue: imageableMargins forKey: PAPER_IMAGEABLE_MARGINS];

            [outputArray addObject: paperProps];

            CFRelease(paperName);
            CFRelease(localised);
            paperName = NULL;
            localised = NULL;
        }
    }
    @finally
    {
        if (paperName) CFRelease(paperName);
        if (localised) CFRelease(localised);
    }

    return outputArray;
}


I actually implemented this as a category on NSPrinter. You can do this too by simply creating the following header:


#import <Cocoa/Cocoa.h>

#define PAPER_NAME               @"paper_name"
#define LOCALISED_PAPER_NAME     @"localised_paper_name"
#define LOCALIZED_PAPER_NAME     @"localised_paper_name"
#define PAPER_SIZE               @"paper_size"
#define PAPER_IMAGEABLE_MARGINS  @"printable_margins"

@interface NSPrinter (MyNSPrinterExtensions)

// returns an NSArray of NSDictionaries: see constants above.
+ (NSArray *)paperSizesAndNamesForPrinter: (NSString *)printerName;
+ (NSArray *)extractInfoFromPrinter: (PMPrinter)printerInfo;

@end


Finally, you’d then wrap the above two functions in



@implementation NSPrinter (MyNSPrinterExtensions)

...
..
.

@end


Sorry if you’ve got a small screen and this article scrolls horizontally. I’ve decided that, unlike other languages that I can easily keep to 80 columns (or even 65 for writing articles), Objective-C simply requires huge amounts of horizontal real estate.

Also, like most of my code, this uses the new Objective-C structured exception handling, which requires Mac OS X 10.3.9 or greater. If you’re not using it, you should be. I was slow to get into SEH when I first saw them many years back, but now I feel any language is incomplete without them.

[Read Rest of Article]
Sep 26, 2006 | 06:33:05
JiaId3 0.9.1 Released
By marcwan

I am happy to announce the immediate availability of JiaId3 0.9.1. New features in this release include:

  • Fixed bugs that caused error dialogs to pop up on Intel Macs as well as some Panther systems.
  • I fixed up the .dmg so that it looks a bit better when you mount and show it for the first time.

I have actually coded up a lot of FLAC support, but it is currently disabled, as FLAC files appear to have a number of wild permutations, including native FLAC format, FLAC embedded in Ogg streams, and weird FLAC/ID3 hybrids that are widely seen but not supported by any available code base.

You can download the (Universal Binary) .dmg file from:

http://chipmunkninja.com/download/JiaId3-0.9.1.dmg

More details about JiaId3 can be found in the following locations:

As always, any comments, questions, or bug reports should be sent to me. I’d love to hear from anybody using the program.

[Read Rest of Article]
Sep 20, 2006 | 19:56:12
Rotating an NSImage object in Cocoa
By marcwan

I recently started working on an image viewing program for Mac OS X using Cocoa, and one of the features I decided to add was the ability to rotate images in 90° increments. I did some searching on the internet, and found a few things:

Neither of the first two was exactly what I wanted—the first didn’t quite work, while the second was too complicated and, in order to support arbitrary rotation, created an NSImage object that was way too large.

[Read Rest of Article]
Sep 01, 2006 | 07:20:54
Version 0.9.0 of JiaId3, an Audio File Tag Editor, now Available
By marcwan

I am happy to announce the immediate availability of version 0.9.0 of JiaId3. The big change in this version is support for Ogg/Vorbis (.ogg) audio files. I have also seriously cleaned up error handling and added some architecture to support more audio file formats as I learn about them.

JiaId3 0.9.0 can be downloaded from:

http://chipmunkninja.com/download/JiaId3-0.9.0.dmg

The source code can be downloaded from:

http://chipmunkninja.com/download/JiaId3-0.9.0.src.tar.gz

About JiaId3

JiaId3 0.9.0 is an information tag editor for your audio files. It currently supports editing the ID3 information associated with MP3 files, as well as the tag information associated with Ogg/Vorbis .ogg files. I will add support for more file formats as I approach version 1.0.0. I first sat down to write this application when I found a directory on my hard disk with a bunch of “junk” MP3 files whose tag information was all messed up. Instead of throwing them all away, or having them mess up my audio libraries, I set about to write an application to let me fix them.

[Read Rest of Article]
Aug 24, 2006 | 03:40:51
Announcing JiaId3, A Mac OS X Audio file tag Editor
By marcwan
JiaId3 0.8.0 is an information tag editor for your audio files. It currently supports editing the ID3 information associated with MP3 files, and I’ll add support for more file formats as I approach version 1.0.0. I first sat down to write this application when I found a directory on my hard disk with a bunch of “junk” MP3 files whose tag information was all messed up. Instead of throwing them all away, or having them mess up my audio libraries, I set about to write an application to let me fix them.

JiaId3 version 0.8.0 can be downloaded from:

http://chipmunkninja.com/download/JiaId3-0.8.0.dmg

[Read Rest of Article]
Aug 21, 2006 | 01:06:55
When Apples go Bad
By marcwan

Last night, after a nice weekend of varying activities (yoga, studying, yoga, sleeping), the plan was to lie in bed and read some Apple Developer Connection documentation for a while and generally learn more about some stuff I’ve been working on lately.

So, it was with some dismay that I sat down with Samantha’s PowerBook G4, clicked on Safari and got … nothing. The icon bounced twice and then stopped. System logs showed nothing, and the application appeared to be all fine in its folder in /Applications.

Uuuuuh. Now what? Oh yes, the System Console, in /Application/Utilities. It gave me the following very helpful message:

2006-08-20 22:32:29.825 Safari[249] Unable to load nib file: MainMenu, exiting

[Read Rest of Article]
Jun 16, 2006 | 06:51:45
The End of Mac OS X
By marcwan

Today I had a glimpse into the future of Apple’s Mac OS X, and I was more than a little frightened.

When I think about why I use my Powerbook so much and shun Windows whenever possible, the reasons are not what most people might think. I don’t care about the cost (okay, 200$ USD for Windows is a bit much, but I happily paid 130$ USD for the 10.4 “Tiger” Upgrade to OS X on our 12” Powerbook), and while I’m more than a little alarmed by the security problems endemic in Windows, I can avoid many of them by using Firefox, and Microsoft is slowly learning how to do the automated patching game.

[Read Rest of Article]
Oct 15, 2005 | 14:52:40
Finding the Love
By marcwan

In March of this year, having largely finished writing my first book on web application programming with PHP and MySQL, I realised it was time to find another contract. I hadn’t worked in nearly a year, and the reserves were getting a little bit lower than I would normally like.

Around then, I started getting a number of emails and phone calls from people interested in having me come work for them for a while. Most of the jobs were to write some .NET applications or tools, or otherwise C/C++ things related to OLE2/COM that I did all the time when I worked for Microsoft in the 1990s. The money for these contracts is usually good, and I was relieved to learn I wasn’t going to be smashing open the piggy bank for extra funds.

[Read Rest of Article]
Jun 17, 2005 | 17:33:17
Installing PHP, MySQL, and Apache on Mac OS X
By marcwan

Many Mac OS X users seem to be having problems getting AMP (Apache, MySQL, and PHP) working properly on various versions of the operating system. In this article, I will describe the process by which I did this on my Powerbook which started out running Panther (10.3) and then Tiger (10.4) (the instructions are the same for both OSes).

[Read Rest of Article]
Copyright © 2005-2008 Marc Wandschneider All Rights Reserved.