A way to enable a LaunchDaemon to output sound?
Posted
by Varun Mehta
on Stack Overflow
See other posts from Stack Overflow
or by Varun Mehta
Published on 2010-06-10T01:14:38Z
Indexed on
2010/06/10
1:22 UTC
Read the original article
Hit count: 316
I have a small Foundation application that checks a website and plays a sound if it sees a certain value. This application successfully plays a sound when I run it as my user from the Terminal.
I've configured this app to run as a LaunchDaemon, with the following plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.myorg.appidentifier</string>
<key>ProgramArguments</key>
<array>
<string>/Users/varunm/path/to/cli/application</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
When I have this service launched I can see it successfully read in and log values from the website, but it never generates any sound. The sound files are located in the same directory as the binary, and I use the following code:
NSSound *soundToPlay = [[NSSound alloc] initWithContentsOfFile:@"sound.wav" byReference:NO];
[soundToPlay setDelegate:stopper];
[soundToPlay play];
while (g_keepRunning)
{
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
}
[soundToPlay setCurrentTime:0.0];
Is there any way to get my LaunchDaemon application to play sound? This machine gets run by different people, and sometimes has no one logged in, which is why I have to configure it as a LaunchDaemon.
© Stack Overflow or respective owner