Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
bit of an issue here... i've been playing around with menu bar applications and i can't seem to make a new window key when opening one from the menulet's pull down menu.

i can understand (kinda/sorta) why it's not working, because the application is only running in the background, so opening a new window from this background app shouldn't make the window key because the app isn't key, or something like that.

but other menu bar apps like "Google Notifier" have selectable popup windows (like Preferences, etc.) that are always made key and ordered front when selected...

is there some secret to doing this?

i built a small test app to demonstrate this so you can see what's happening. the first time you build the app and select the window to open, it will be the key app, but only because you just built from xcode. But if you launch the build from Finder (included), or while the app is running after being built from xcode if you then select Finder (or any other app) and then open the popup window from the menulet it will not be key, eventhough my code tells the window to become key and ordered front...

help here would be great.
 

Attachments

  • MenuletMakeKeyWindow.zip
    81.8 KB · Views: 126

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
so i'm not sure if this is the standard way to solving this issue, but i managed to make this work by using a simple cocoa-embedded applescript at the start of the IBAction that opens a new window.

Code:
NSString *bringAppToFrontScript = @"\
                                  tell application \"[I]appName[/I]\"\n\
                                  activate\n\
                                  end tell";
NSDictionary *errorDict;
NSAppleEventDescriptor *returnDescriptor = NULL;
NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:bringAppToFrontScript];
returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
[NSAppleScript release];
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
The preferred method of doing this is via
Code:
[NSApp activateIgnoringOtherApps:YES];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.