showing NSAlert from a command-line tool

Discussion in 'Mac Programming' started by keitak, Aug 19, 2010.

  1. keitak macrumors newbie

    Joined:
    Nov 28, 2009
    Location:
    Tokyo
    #1
    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?
     
  2. MorphingDragon macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #2
    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().
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    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
     
  4. keitak thread starter macrumors newbie

    Joined:
    Nov 28, 2009
    Location:
    Tokyo
    #4
    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?
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    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.
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  7. keitak thread starter macrumors newbie

    Joined:
    Nov 28, 2009
    Location:
    Tokyo
    #7
    Ooh... That's exactly what I want! Thanks a lot!
     

Share This Page