LaunchAgent - Is there something like RunAtScreenSaver?

家住魔仙堡 提交于 2020-01-15 09:32:06

问题


I am looking for a way to execute my app (it's a background task) at times, where the machine is "idle". A good incident would be when the screensaver launches. I already read the manual auf launchd and already use a LaunchAgent to lauch my app at certain intervals, but I found nothing that might help me launching my app when the screensaver is active.

Is there any possibility to do that?

Thanks in advance!

Josh


回答1:


Have another process that runs in the background and listens for distributed notifications named com.apple.screenIsLocked and com.apple.screenIsUnlocked. (That's for Snow Leopard. Leopard used different notification names. Use Notification Watcher and experimentation to find out what they are.) When one of those notifications comes in, launch or nicely-quit* your real app, as appropriate.

*You'll want to use an Apple Event for this.




回答2:


For Snow Leopard the screenIsLocked and screenIsUnlocked notifications aren't available anymore. What I've used successfully are these:

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(locked:) name:NSWorkspaceScreensDidSleepNotification object:nil];

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(unlocked:) name:NSWorkspaceScreensDidWakeNotification object:nil];



回答3:


I'm a new user, so I can't comment on or vote up portenkirchner's suggestion. Matt Swann has moved his ScriptSaver.

It does exactly what I want, run an AppleScript program when I unlock the screensaver.




回答4:


You can use ScriptSaver by Matt Swann. This is a Mac OS X screensaver which can run AppleScripts when it activates and deactivates.

http://swannman.wordpress.com/projects/scriptsaver/



来源:https://stackoverflow.com/questions/1443243/launchagent-is-there-something-like-runatscreensaver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!