Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the following shell script to toggle the enabled state of a Mac OS X service:</p> <pre><code>#!/bin/sh # toggle OS X service if [ "$#" -ne "1" ] then echo 1&gt;&amp;2 Usage: `basename $0` service echo 1&gt;&amp;2 Toggle the enabled state of the given service. exit 2 fi SERVICE_NAME=$1 SERVICE_PLIST=/System/Library/LaunchDaemons/$SERVICE_NAME.plist if [ ! -f "$SERVICE_PLIST" ] then echo 1&gt;&amp;2 Service $SERVICE_NAME is not available. exit 1 fi /sbin/service --test-if-configured-on "$SERVICE_NAME" if [ $? -eq 0 ] then /bin/launchctl unload -w "$SERVICE_PLIST" else /bin/launchctl load -w "$SERVICE_PLIST" fi </code></pre> <p>The script uses the <a href="http://www.manpagez.com/man/8/service/" rel="nofollow noreferrer">service</a> command to determine if the service is on and then toggles its state by invoking <a href="http://www.manpagez.com/man/1/launchctl/" rel="nofollow noreferrer">launchctl</a>.</p> <p>The name of the service has to passed as the only argument. To toggle web sharing run:</p> <pre><code>sudo toggle_service.sh org.apache.httpd </code></pre> <p>To invoke the shell script via AppleScript you can use the <a href="http://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW40" rel="nofollow noreferrer">do shell script</a> command:</p> <pre><code>do shell script "toggle_service.sh org.apache.httpd" password "pwd" with administrator privileges </code></pre> <p>Use the <code>password</code> parameter to avoid being prompted.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload