Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

keitak

macrumors newbie
Original poster
Nov 28, 2009
14
0
Tokyo
Hi, I have a tool that runs in the background via launchd and I need it to show a NSAlert to the currently logged in user.... what do you guys think the best way to do this is?
 
Hi, I have a tool that runs in the background via launchd and I need it to show a NSAlert to the currently logged in user.... what do you guys think the best way to do this is?

NSAlert is part of AppKit, you need to import that header file into your program. Then you can use the NSAlert class or use NSRunAlertPanel().
 
A Foundation tool (Obj-C), or a plain C tool, or a C++ tool?

Is the tool running as a launch daemon or a launch agent?

Have you read TN2083?
http://developer.apple.com/mac/library/technotes/tn2005/tn2083.html

It's a foundation tool, running as a launch daemon - I actually haven't read TN2083 before but I was just scanning over it, it looks like launch daemons don't have access to WindowServer...

So, I wouldn't be able to do what I'm trying to do...right?
 
So, I wouldn't be able to do what I'm trying to do...right?

Right.

However, almost anything running as a launch daemon can easily be moved to the LaunchAgents folder, where it then runs as a launch agent. I could be wrong, but I don't think there's anything a daemon can do that is prohibited for agents. The last few things I worked on that fell into agent/daemon-ness I simply deployed as launch agents, and I didn't hit any prohibitions. As I recall, the main thing launch daemons get is a launch at an earlier point in time.

If the agent/daemon is running as root, there are a number of security things you have to take into account when interacting with users. So sometimes the safest thing is to start another process with a less privileged uid, and communicate with some form of inter-process messaging. Sockets is one way (lo0 loopback TCP/IP), but there are others. Whatever it is, it has to be secure, in the sense that privileged side won't accept unprivileged messages commanding any unauthorized privileged action.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.