Re: highlighting menu item in main menu bar
Re: highlighting menu item in main menu bar
- Subject: Re: highlighting menu item in main menu bar
- From: "email@hidden" <email@hidden>
- Date: Sat, 6 Jun 2009 16:29:19 -0700
At 11:10 AM -0700 6/1/09, Peter Ammon wrote:
Hi Ken,
The menu item unhighlights after the menu item's action is finished.
If user input should be blocked while the script is running, then
you should register for the NSTaskDidTerminateNotification and then
drive the main run loop forwards from within your menu item's action
method, until you get the notification.
hi peter,
so i tried this as follows:
register for the NSTaskDidTerminateNotification
launch my sub task (that executes a selected applescript)
drive the main run loop until my registered notification
routine sets a global
return from my action method
and while this does indeed keep the menu item in the main menu bar
highlighted, it seems to block any apple events from being executed
within my app.
i've been "driving the run loop forward" as follows:
while (!globalVar)
[[NSRunloop <runloop>] runMode: <mode>
beforeDate: [NSDate dateWithTimeIntervalSinceNow: .1]];
where <runloop> is either currentRunLoop or mainRunLoop
and <mode> is either:
NSDefaultRunLoopMode
NSRunLoopCommonModes
NSConnectionReplyMode
NSModalPanelRunLoopMode
NSEventTrackingRunLoopMode
or [[NSRunloop <runloop>] currentMode]
i believe my code is basically correct for 2 reasons:
1) if i don't do any of this, then the selected scripts work
fine, but the menu item in the main menu bar does not remain
highlighted, as my action method returns as soon as its launched the
subtask; and
2) if i do the above, the subtask eventually times out, the
menu item unhighlights, but of course the subtask was unable to
execute the applescript. (note that i can [force] quit my subtask via
activity monitor and then the menu bar item unhighlights and my app
proceeds appropriately.)
so... is there some run loop mode i have to be in to allow
applescripts/apple events to execute? alternatively, is there some
other way to keep the item in the main menu bar highlighted until my
subtask completes executing the applescript?
thanx,
ken
On the other hand, if the user can continue using your app as
normal, you should not show the menu item highlighted, because the
user might want to choose different menu items.
On Jun 1, 2009, at 9:34 AM, email@hidden wrote:
my app has a scripts menu item (in the main menu bar). the items in
this menu correspond to applescript files the user has placed in my
application support folder. when the user selects one of these menu
items, i execute the appropriate script. i execute the script in a
(sub) task (NSTask). i do it this way because i discovered (the
hard/empirical way) that if an executing script, executes
functionality in my app that calls -[NSScriptCommand
suspendExecution], then the executing of that script will
erroneously terminate early. using a sub task solves this problem.
in my app, when i launch this task, i register for the
NSTaskDidTerminateNotification and in my notification routine, i
display any errors returned.
this all works fine... except that as soon as i return from
launching the sub task, the menu item (in the main menu bar) for
the scripts menu un-highlights. i would like this to remain
highlighted until my notification routine is called, in order to
provide feedback to the user that his/her script is still executing.
is this possible? if so, could someone provide any code and/or
documentation pointers?
thanx,
ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden