How to add an application icon to OS X Dock through Desired Configuration Management

19 users found this article helpful

Information

To add an application icon to the OS X Dock through Desired Configuration Management, you can create a script with appropriate instructions and include it in a configuration item that will be used to evaluate Macs for compliance.

Note: This article does not provide details about setting up and using Desired Configuration Management. For the complete information about creating configuration items and evaluation scripts, please read the Desired Configuration Management section (including the Using Scripts to Assess Compliance sub-section) of the Parallels Management Suite for Microsoft SCCM 2012 Administrator’s Guide.

Follow the instructions provided in the guide (see link above) and open the Create Configuration Item Wizard. When specifying the settings on the Create Setting dialog, create a discovery script as follows:

  1. In the Setting type list box, select Script.
  2. In the Data type list box, select String.
  3. In the Discovery script section, click Add Script.
  4. In the Edit Discovery Script dialog, copy and paste the following script in the Script edit box (change the value of the APP_PATH variable to contain a path to your app):

    APP_PATH="/Applications/Photo Booth.app"
    if [[ ! -d ${APP_PATH} ]]; then
        exit 0 # Silently exit if the application is not installed
    fi
    encodedAppPath=$(python -c "import urllib; print urllib.quote(\"${APP_PATH}\");")
    for user in $(dscl . -list /Users)
    do
        userHome=$(dscl . -read /Users/${user} | grep 'NFSHomeDirectory:' | awk '{print $2}')
        dockPrefs=${userHome}"/Library/Preferences/com.apple.dock.plist"
        if [[ ! -f ${dockPrefs} ]]; then
            continue
        fi
        sudo -u ${user} /usr/bin/defaults read com.apple.dock persistent-apps | grep "${encodedAppPath}" > /dev/null 2>&1
        if [[ $? == 0 ]]; then
            continue
        fi
        sudo -u ${user} /usr/bin/defaults read com.apple.dock persistent-apps | grep "${APP_PATH}" > /dev/null 2>&1
        if [[ $? == 0 ]]; then
            continue
        fi
        # Need to add icon for at least one user
        echo "No icon for \"${user}\""
        exit 0
    done
    echo "OK"
    exit 0
    

When done adding the discovery script, close the Edit Discovery Script dialog.

You now need to add a remediation script using the following steps:

  1. On the Creating Setting dialog, click the Add Script button located the Remediation script section.
  2. In the Create Remediation Script dialog, copy and paste the following script in the Script edit box (change the value of the APP_PATH variable to contain a path to your app):

    APP_PATH="/Applications/Photo Booth.app"
    if [[ ! -d ${APP_PATH} ]]; then
        echo "Application \"${APP_PATH}\" not found" 1>&2
        exit 1
    fi
    encodedAppPath=$(python -c "import urllib; print urllib.quote(\"${APP_PATH}\");")
    iconDesc=
    read -d '' iconDesc << EOF
        <dict>
            <key>tile-data</key>
            <dict>
                <key>file-data</key>
                <dict>
                    <key>_CFURLString</key>
                    <string>$APP_PATH</string>
                    <key>_CFURLStringType</key>
                    <integer>0</integer>
                </dict>
            </dict>
        </dict>
    EOF
    for user in $(dscl . -list /Users)
    do
        userHome=$(dscl . -read /Users/${user} | grep 'NFSHomeDirectory:' | awk '{print $2}')
        dockPrefs=${userHome}"/Library/Preferences/com.apple.dock.plist"
        if [[ ! -f ${dockPrefs} ]]; then
            continue
        fi
        sudo -u ${user} /usr/bin/defaults read com.apple.dock persistent-apps | grep "${encodedAppPath}" > /dev/null 2>&1
        if [[ $? == 0 ]]; then
            continue
        fi
        sudo -u ${user} /usr/bin/defaults read com.apple.dock persistent-apps | grep "${APP_PATH}" > /dev/null 2>&1
        if [[ $? == 0 ]]; then
            continue
        fi
        sudo -u ${user} /usr/bin/defaults write com.apple.dock persistent-apps -array-add "${iconDesc}"
        sudo -u ${user} killall -HUP Dock
    done
    echo "OK"
    exit 0
    

When done adding the remediation script, click OK to close the Create Remediation Script dialog.

After creating the discovery and the remediation scripts, create a compliance rule as follows:

  1. Click the Compliance Rules tab in the Create Setting dialog.
  2. Click New to open the Create Rule dialog.
  3. Type in the rule name and an optional description.
  4. In the Rule type list box, select Value.
  5. In The value returned by the specified script list box, select Equals.
  6. In the following values edit box, type “OK” (without quotes).
  7. Select the Run the specified remediation script when this setting is noncompliant option.
  8. Click OK and then click OK again to return to the Create Configuration Item Wizard.

Complete the wizard as described in the Parallels Management Suite for Microsoft SCCM 2012 Administrator’s Guide.

Was this article helpful?

Tell us how we can improve it.