Posted on 06-13-2016 05:44 AM
Hello,
I'm trying to disable apple Notification Center, i'm working on a campus so i want to make a package or script so i can deploy this with our deployment solution.
Whenever i start a terminal and type:
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
The command does exactly what i want to accomplish. But whenever this command is executed from within a package it's just not working, even with SIP disabled.
Please Help.
Posted on 06-13-2016 02:29 PM
LaunchAgents run as the user. LaunchDaemons run as root. As you are running the command via Casper, the script runs as 'root' and unloads notification center for the root user. When you run the command yourself, you're running it as the local user and not as root.
Try this DerFlounder post about running the script as the user.
https://derflounder.wordpress.com/2016/03/25/running-processes-in-os-x-as-the-logged-in-user-from-outside-the-users-account/
Posted on 06-13-2016 11:13 PM
Thanks so far i created this script:
logged_in_user=python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'
logged_in_user_uid=id -u "$logged_in_user"
/bin/launchctl asuser "$logged_in_user_uid" unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
exit 0 ## Success
exit 1 ## Failure
When running this script i see the following message:
User$ /Library/Application Support/JAMF/Composer/Sources/Disable.NotCentre.2016/Scripts/postinstall ; exit;
This subcommand requires root privileges: asuser
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Proces voltooid]
What is the right command to use to accomplish this or is it just not possible on el capitan?
Posted on 06-14-2016 12:23 AM
I found the right script here: https://jamfnation.jamfsoftware.com/discussion.html?id=9902
Credits to Josh.Smith
Script:
loggedInUser=$( ls -l /dev/console | awk '{print $3}' )
loggedInUID=$(id -u $loggedInUser)
/bin/launchctl asuser $loggedInUID sudo -iu "${loggedInUser}" "launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist"
exit 0 ## Success
exit 1 ## Failure
Posted on 06-14-2016 01:17 AM
Does anyone know if it's possible to run the above without logged in user account?
Posted on 06-27-2016 04:50 AM
Maybe my knowledge of scripting isn't very good but i managed to disable notificationcenter without user interaction, once disabled all required stuff will be removed on next reboot.
If someone with more scripting knowledge knows a better/simpler way to accomplish this then please share your thoughts.
I created the following and used composer to create the package:
/Library/LaunchAgents/local.disablenotcenter.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>local.disablenotcenter.plist</string>
<key>LimitLoadToSessionType</key>
<string>Aqua</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Scripts/DisableNotCenter.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
/Library/LaunchDaemons/local.disablenotcenter.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>local.disablenotcenter</string>
<key>Program</key>
<string>/Library/Scripts/DeleteScriptAgentDaemon.sh</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
/Library/Scripts/DeleteScriptAgentDaemon.sh
.#!/bin/bash
.#Disable Notification Center
doc=/temp/notcenterdisabled.txt
if [ ! -f $doc ]
then
exit 0
else
.# Unload LaunchAgent
/bin/launchctl unload /Library/LaunchAgents/local.disablenotcenter.plist
.# Remove LaunchAgent
/usr/bin/srm -f /Library/LaunchAgents/local.disablenotcenter.plist
.# Remove DisableNotCenter.sh
/usr/bin/srm -f /Library/Scripts/DisableNotCenter.sh
.# Remove Helper Daemon
/usr/bin/srm -f /Library/LaunchDaemons/local.disablenotcenter.plist
.# Remove temp dir
/usr/bin/srm -Rf /temp
.# Make script self-destruct
/usr/bin/srm $0
fi
exit 0
/Library/Scripts/DisableNotCenter.sh
.#!/bin/bash
.#Disable Notification Center
.# Sleeping for 5 seconds
sleep 5
.# Unload Notification Center
/bin/launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
/usr/bin/touch /temp/notcenterdisabled.txt
exit 0
Also created a directory in the root and named it temp with read write acces for everyone
Posted on 05-22-2017 01:00 PM
Does anyone know a method that does not require turning off SIP?