Menu bar app windows won't move to front

Hay guys, Ive got an applescript objec app that runs in the menu bar.

It has no dock icon because I used the “Application is agent (UIElement)” key in the apps info.plist

When a user selects “preferences” from the menu bar, the prefs window opens but it always opens in the background.

Ive connected the menu bar item to the main window in interface builder using “makeKeyAndOrderFront:” but it still opens in the background. The “about” box also opens in the background.

Ive read online that [NSApp activateIgnoringOtherApps:YES]; will solve this, but im usure how to add this to my project because Im writing everything in applescript except the menulet itself.

Any help would be appreciated.

Hi,

try

current application's NSApplication's sharedApplication()'s activateIgnoringOtherApps_(true)

Thanks Stefan, where abouts should I put that? I tried putting under awakeFromNib and onApplicaionFinnishLaunching but it didnt seem to have any effect.

I dont have any “open window” code at the moment just the link in Interface Builder. If that makes sense.

Probably you have to write a custom IBAction method to open the preference window.
The “open window” connection in Interface builder must be connected to the custom method.
In the method add the activateIgnoringOtherApps() line and another line to call the previous “open window” selector programmatically

Im struggling a bit with creating the open window code. Would it be possible for me to convert

windowController = [[NSWindowController alloc] initWithWindowNibName:@"Preferences"]

into AppleScript ObjeC to use in my app delegate maby? A bit like the activateIgnoringOtherApps was modified to fit.

[Edit]

Or now that I think of it, is there applescript that could talk to the .xib file directly?

I don’t understand.
If there is an IBAction method to respond to selecting the menu item “Preferences”, put the
activateIgnoringOtherApps line in there, obviously it’s Objective-C so use the ObjC code.

Sorry Ive not really gotten to grips with IBActions and such yet my fault.

But I managed to get it working without having to use any.

I added this code to my script

    
    property prefsWindow : missing value

on openPrefsWindow_(sender)
        
        tell prefsWindow to makeKeyAndOrderFront_(me)
        tell application "Logic Pro AutoSave" to activate
        
        end openPrefsWindow_

In interface builder I connected the menu item to openPrefs_

Then Connected the prefs window to property prefsWindow : missing value

And it is popping up fine now :slight_smile: thanks for your help.

This worked for me too. In fact you can use

tell current application to activate