How to reset OS X volume after sleep using launchd? I'm been trying to write a plist file on which when I return from sleep mode, I always want to make my Mac volume to the minimum amount. However, it looks like the following plist doesn't work, with an error: 1:1: syntax error: Expected string but found end of script. (-2741)

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
    &lt;dict&gt;
        &lt;key&gt;KeepAlive&lt;/key&gt;
        &lt;false/&gt;
        &lt;key&gt;Label&lt;/key&gt;
        &lt;string&gt;my.plist&lt;/string&gt;
        &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;/usr/bin/osascript&lt;/string&gt;
            &lt;string&gt;-e&lt;/string&gt;
            &lt;string&gt;"&lt;/string&gt;
            &lt;string&gt;set&lt;/string&gt;
            &lt;string&gt;volume&lt;/string&gt;
            &lt;string&gt;output&lt;/string&gt;
            &lt;string&gt;volume&lt;/string&gt;
            &lt;string&gt;0&lt;/string&gt;
            &lt;string&gt;"&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;RunAtLoad&lt;/key&gt;
        &lt;true/&gt;
    &lt;/dict&gt;
&lt;/plist&gt;


Also, when the following is not working:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
    &lt;dict&gt;
        &lt;key&gt;KeepAlive&lt;/key&gt;
        &lt;false/&gt;
        &lt;key&gt;Label&lt;/key&gt;
        &lt;string&gt;my.plist&lt;/string&gt;
        &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;/usr/bin/osascript&lt;/string&gt;
            &lt;string&gt;-e&lt;/string&gt;
            &lt;string&gt;"set volume output volume 0"&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;RunAtLoad&lt;/key&gt;
        &lt;true/&gt;
    &lt;/dict&gt;
&lt;/plist&gt;


The osascript command functions well if I execute it from within Terminal, so I think it's due to how I set my arguments list to the plist.

So is it feasible to take the string argument like "~" in launchd? Or is there some other things that I'm missing here?

I suspect that it might be better to write the osascript command in shell script, and load the shell script to enable the Mac's volume to minimize... but is it the correct approach?

I use OS X Mavericks 10.9.2.
The second launchd job ticket format is almost correct. Only a set of quotes need removing.

Quotes

The quotes are no longer needed in the second launchd job ticket, so change:

&lt;string&gt;"set volume output volume 0"&lt;/string&gt;


…to…

&lt;string&gt;set volume output volume 0&lt;/string&gt;


Grouping Arguments

In this case, the quotes grouped the set of arguments for osascript to see as one item. Thus osascript gets two arguments, the flag -e and the script. This meets the requirements from the osascript manual.

When called through Terminal.app and thus through the shell, the quotes are needed to perform the grouping. When osascript gets the arguments, the shell has removed the quotes.

Without quotes, spaces subdivide each item passed via the shell.

When called through a launchd job ticket, the grouping is intrinsic within the array passed as ProgramArguments. In your first ticket, the array contained nine items and in the second ticket, the array contained three.

LaunchAgent

Be sure to add this launchd job as a ~/Library/LaunchAgents as osascript requires an active user with a graphical session.

This approach approximates what I do with Power Manager in How to Set the Volume When Logging In.