Re: delayed NSWorkspaceDidTerminateApplicationNotification under 10.6?
Re: delayed NSWorkspaceDidTerminateApplicationNotification under 10.6?
- Subject: Re: delayed NSWorkspaceDidTerminateApplicationNotification under 10.6?
- From: Dave Keck <email@hidden>
- Date: Wed, 8 Sep 2010 18:13:46 -0400
> > Anyway, I ended up using the Process Manager APIs
> > to check whether the app in question was running before executing an
> > AppleScript to issue commands to it.
>
> It's worth a try. But I'm afraid it will put a heavy load on the CPU
> for a timer firing every second, no?
You'll have to profile it and see. Of course, you should try to
minimize the amount of polling.
> > (It seems NSRunningApplication is the
> > modern API for 10.6+.)
>
> Do we know if this is faster than using Process Manager? Unfortunately
> I need to target Mac OS X 10.5 as well (where this is not a problem),
> but I suppose I could use NSSelectorFromString() to get it to compile
> under the 10.5 SDK.
I don't think performance is going to be a big issue with the process
APIs; at any given time a user probably isn't going to have over 20 or
30 foreground+background apps running, so even iterating over each one
shouldn't be much an issue. But no need to speculate – might as well
just profile the different techniques and choose the best one.
> > /snip.../
> >
> > I only know enough about AppleScript to avoid it, but I believe iTunes is
> > being launched necessarily for the NSAppleScript to compile.
>
> No, this is not correct. You can compile a script without launching
> the target - at least on Snow Leopard.
I'm afraid my testing shows otherwise; on my system, the following
code always launches Safari on both 10.5 and 10.6:
[[[[NSAppleScript alloc] initWithSource: @"tell application id
\"com.apple.Safari\" to activate"] autorelease] compileAndReturnError:
nil];
(Note it's -compileAndReturnError:, not executeAndReturnError:.) The
launching behavior seems to vary by application, though. For me, this
code launches iSync, Safari and System Preferences, but doesn't seem
to launch iTunes.
Such unpredictability is the nature of AppleScript and why I try to
avoid it. But I imagine this (or some related reason) is why you're
having relaunching issues, though I bet it depends on the system.
... So to workaround the problem, check whether iTunes is running, and
only if it is, perform some Scripting Bridge/AppleScript action.
_______________________________________________
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