当 iTunes 启动时启动 Mac 应用程序,无需后台进程(如 last.fm)

发布于 2024-12-03 05:15:26 字数 784 浏览 2 评论 0原文

我想在 iTunes 加载时启动我的 OSX 应用程序,而无需后台进程来监视 iTunes 启动时间。 last.fm 客户端似乎就是这么做的;当 iTunes 关闭时,我找不到后台进程,但一旦启动,last.fm 应用程序就会随之打开。也许它正在使用某种可以启动另一个进程的 iTunes 插件?

使用后台进程执行此操作似乎相当简单,但我想在没有后台进程的情况下执行此操作,这样我的程序就不会使用系统资源。

使用后台进程的一种选择是使用 NSWorkspace 的通知中心,例如:

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(appDidLaunch:) name:NSWorkspaceDidLaunchApplicationNotification object:nil]

但是,这显然需要后台进程。我发现的另一个选择是使用 ProcessNotif,如下所示:

ProcessNotif *x = [[ProcessNotif new] autorelease];
[x setProcessName: @"iTunes"];
[x setTarget: self];
[x setAction: @selector(doStuff)];
[x start];

这可能比 NSWorkspace 方法更不理想,而且它也需要后台进程。

那么,有什么方法可以在启动时从 iTunes 启动,而不需要后台进程吗?

谢谢!

I would like to start my OSX application when iTunes loads, without having a background process to monitor when iTunes launches. The last.fm client seems to do this; I can find no background process when iTunes is closed, but as soon as it starts the last.fm app opens right along with it. Perhaps it is using some kind of iTunes plugin that can start another process?

It seems to be fairly trivial to do this with a background process, but I'd like to do it without one so my program isn't using system resources.

One option with a background process is to use NSWorkspace's notification center, such as:

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(appDidLaunch:) name:NSWorkspaceDidLaunchApplicationNotification object:nil]

However, this obviously requires a background process. Another option I found was to use ProcessNotif, something like this:

ProcessNotif *x = [[ProcessNotif new] autorelease];
[x setProcessName: @"iTunes"];
[x setTarget: self];
[x setAction: @selector(doStuff)];
[x start];

This is probably even less ideal than the NSWorkspace method, and it too requires a background process.

So, is there some way to launch from iTunes when it launches, no background process required?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅的被狗咬 2024-12-10 05:15:26

last.fm 客户端通过安装 iTunes 插件来实现这一点。该插件会在 iTunes 启动时加载,然后有机会启动 last.fm 应用程序。要创建插件,您需要此处。

The last.fm client achieves that by installing an iTunes plugin. This plugin gets loaded when iTunes starts and then has a chance to start the last.fm app. To create a plugin you need the iTunes PlugIn SDK available here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文