Tuesday, December 12, 2017

#1 2013-01-26 08:12:28 am

PeacheyMcKeitch
Member
From:: Scotland
Registered: 2012-12-21
Posts: 37
Website

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.


David McKeitch Sound Services
www.davidmckeitch.com

Offline

 

#2 2013-01-26 08:18:21 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Menu bar app windows won't move to front

Hi,

try

Applescript:

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


regards

Stefan

Offline

 

#3 2013-01-26 08:43:22 am

PeacheyMcKeitch
Member
From:: Scotland
Registered: 2012-12-21
Posts: 37
Website

Re: Menu bar app windows won't move to front

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.


David McKeitch Sound Services
www.davidmckeitch.com

Offline

 

#4 2013-01-26 08:51:00 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Menu bar app windows won't move to front

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

Last edited by StefanK (2013-01-26 08:51:31 am)


regards

Stefan

Offline

 

#5 2013-01-26 11:27:36 am

PeacheyMcKeitch
Member
From:: Scotland
Registered: 2012-12-21
Posts: 37
Website

Re: Menu bar app windows won't move to front

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

Applescript:

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?

Last edited by PeacheyMcKeitch (2013-01-26 12:06:37 pm)


David McKeitch Sound Services
www.davidmckeitch.com

Offline

 

#6 2013-01-26 12:22:11 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11482
Website

Re: Menu bar app windows won't move to front

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.


regards

Stefan

Offline

 

#7 2013-01-26 01:58:25 pm

PeacheyMcKeitch
Member
From:: Scotland
Registered: 2012-12-21
Posts: 37
Website

Re: Menu bar app windows won't move to front

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

Applescript:


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 smile thanks for your help.


David McKeitch Sound Services
www.davidmckeitch.com

Offline

 

#8 2015-11-09 05:10:04 pm

mrpires
Member
Registered: 2010-11-16
Posts: 20

Re: Menu bar app windows won't move to front

PeacheyMcKeitch wrote:

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

Applescript:


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 smile thanks for your help.


This worked for me too. In fact you can use

Applescript:

tell current application to activate

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)