On Mon, Feb 9, 2009 at 10:54 AM, Kevin Martin <ke...@khn.org.uk> wrote:
> Hi,
>
> I am pretty new to Cocoa and Objective C, so please forgive me if the answer
> is obvious. I have done a search of the archive and have found a few people
> experiencing the same problem - but no solution.
>
> I have a console application that I want to be able to run on both Windows
> and OS X, The only real UI related task I have is to prompt for paths for
> loading and saving files. I really prefer a nice dialog to asking the user
> to enter a path on the console.
>
> For the OS X version of the code I see that NSSavePanel and NSOpenPanel are
> what I'm after. I've written what I think is right, but I get no keyboard
> input - or rather it goes to the wrong place. I'm guessing this is because
> there is no NSApplication (and thus no message loop) set up, but this
> doesn't make complete sense to me as mouse events work fine. The input goes
> into the application I launched the my code from, either Terminal or XCode.
>
> I have attached code that should allow you to replicate the problem. I can
> compile it with
>
> g++ nsspprob.mm -framework cocoa
>
> Also, the dialog does not automatically pop up in front of other windows. I
> would like it to do that as well.

You must do two things before using AppKit in any program:

1) Load NSApplication. In a program like this, you should do this by
calling NSApplicationLoad().

2) Register with the window server as an application. Use
TransformProcessType() for this.

You may also need to manually make yourself the frontmost process, you
can do this using SetFrontProcess().

Be aware that accessing the GUI like this from a CLI process is not
really very well supported. You might want to consider writing a small
helper .app instead and calling out to that.

One other note on your code, you do not want to use
NSASCIIStringEncoding to convert the filename to a C string. This will
fail badly for non-ASCII characters, which are perfectly legal in OS X
paths. Use the -fileSystemRepresentation method.

Mike
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to