Need help with LaunchDaemon

yukonluke
New Contributor

Hey all,

I'm trying to disable internal speakers (but leave headphone functionality intact) on some iMacs (currently running 10.11.5).

I'm using the script from here: https://www.jamf.com/jamf-nation/discussions/8965/ot-mute-internal-speakers, with a 10 second sleep built into the while loop.

I've verified that the script works when run from terminal, but I can't seem to get the LaunchDaemon to call the script on Startup.

I've been trying for hours now. So far I've tried:
- Getting rid of the while loop from the script and using the "StartInterval" key instead.
- Using the "KeepAlive" key
- Moving the plist into the "/Library/LaunchAgents/" folder
- Moving the plist into the "~/Library/LaunchAgents/" folder for the local student account
- I've tried without the "AbandonProcessGroup" key

So far, still no love.

I even tried just creating a policy to run the script on login by using the Files & Processes tab. I put in "/Library/Management/disablespeakers.sh &" (I was thinking the ampersand at the end would release the shell), but it just sits at pending and it doesn't work.

Anyways, here's my LaunchDaemon:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
           http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
    <key>AbandonProcessGroup</key>
    <true/>
    <key>Label</key>
    <string>com.yukonluke.ISD</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Library/Management/disablespeakers.sh</string>
    </array>
    <key>RunAtLoad</key>
            <true/>
</dict>
</plist>

Please help me. If I can't get this to work soon, my boss is going to make me take this entire lab apart and manually disconnect the speaker connectors, and I'm hoping that I won't have to do that.

8 REPLIES 8

bvrooman
Valued Contributor

Try this as your ProgramArguments key/array:

<key>ProgramArguments</key>
<array>
    <string>sh</string>
    <string>/Library/Management/disablespeakers.sh</string>
</array>

millersc
Valued Contributor

Make a pkg using Composer to place this plist and the script into respective locations.

Plist = /Library/LaunchAgents
Script option = /usr/local/bin

Remember to have permissions and ownership set correctly. Also use an editor, not TextEdit. TextWrangler is free.
Try below, reboot and report back.

<?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>com.yukonluke.ISD</string>
     <key>Program</key>
     <string>/WHERE/AM_I/LOCATED/disablespeakers.sh</string>
     <key>RunAtLoad</key>
     <true/>
</dict>
</plist>

yukonluke
New Contributor

@bvrooman Hi, thanks for getting back to me.

I tried this. No change in behaviour.

yukonluke
New Contributor

@millersc Hi, thanks for your suggestion.

I tried it out, but this also hasn't resolved my problem.

I've attached an image of the composer breakdown:
cd91588eeba748c0962d013da3b9be3c

The 3 files have the following permissions, which I think are correct:
plist - root:wheel 644
script - root:wheel 755
binary - root:wheel 755

The changes between this and my other package were that you suggested putting the plist into LaunchAgents instead of LaunchDaemons, and in the plist, you subbed in "Program" instead of "ProgramArguments" and you removed the "AbandonProcessGroup" key.

I'm no expert, but I think this plist will need the AbandonProcessGroup key. Otherwise won't it kill the script when the LaunchAgent finishes running?

Thanks again for your help. Please let me know if you have any other suggestions.

yukonluke
New Contributor

Hey all,

I figured it out. It wasn't the launchdaemon at all.

As I mentioned earlier, I was using a script from a previous post, which created a variable: "OUTPUT=audiodevice output ".

The original recommendation was to put the "audiodevice" binary into "/bin", but because of SIP, I couldn't use that location anymore. I instead was using "/usr/local/bin".

Anyways, I changed the variable definition to: "OUTPUT=/usr/local/bin/audiodevice output " and this has resolved my problem.

It's wierd that it worked when I ran the script via terminal, but whatever...

Thanks again for your suggestions.

mm2270
Legendary Contributor III
It's wierd that it worked when I ran the script via terminal, but whatever...

Actually its not really that weird. The most likely problem is that LaunchDaemons don't use the exact same PATH environment as the normal shell in Terminal, so its possible when the script was being run via the LaunchDaemon it could not resolve the path to the audiodevice binary. Putting in the full path as you did resolved it because it no longer needed to figure out the path based on its own PATH environment variables. It worked when run in Terminal because, again, Terminal uses a slightly different PATH environment and was able to resolve it correctly.

Lesson here for anyone paying attention is to put in full paths to binaries in a script whenever possible if you know your script will be run by a LaunchDaemon or any launchd job. It will save you troubleshooting steps later down the line.

yukonluke
New Contributor

@mm2270 Thanks for explaining this so clearly. I felt disappointed in myself once I'd figured it out... ("Why didn't I try using the debug key hours ago!")

I've also observed similar behaviour when I'm trying to run a command via ARD, I would assume for the same reason.

BTW, I'm a big fan and I use the heck out of AutoCasperNBI.

mm2270
Legendary Contributor III
BTW, I'm a big fan and I use the heck out of AutoCasperNBI.

I'm not the author of AutoCasperNBI, that would be @bentoms who deserves the thanks.