Check and Set Computer Settings (OS X) - adenine/Interactive-Installation-Bootstrap GitHub Wiki

Interactive-Installation-Bootstrap

These are scripts that can be used to check if a machine is set up properly for installation and to setup the correct settings for deployment. They are tested for OSX 10.7 only.

Enabling Apple Remote Desktop if SSH is enabled

  1. SSH into the machine
  2. $ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -clientopts -setvnclegacy -vnclegacy yes -clientopts -setvncpw -vncpw mypasswd -restart -agent -privs -all
  • If ssh is not enabled, proceed with the next entry

Create New User from Apple Remote Desktop

  1. Select the machine and open Manage -> Change Client Settings; then click "Continue"
  2. Check "Set Remote Desktop startup preference: Enabled"; Check "Should the Remote Desktop menu be shown? Show status in the menu bar"; then click "Continue"
  3. Check "Yes, create users" and click "Continue"
  4. Add user and click "Continue" (e.g., Name [all lowercase]: cec ; Short Name [all lowercase]: cec)
  5. Check "Set Remote Desktop access mode: Allow access for all local users"; click Privileges...; Check all options EXCEPT "Show when being observed"; click "OK"; Check "Yes, specify access privileges"; click "Continue"
  6. Select your new user and click "Edit"; Check "Set Remote Desktop access for this user: Allow incoming access"; Check "Set privileges to allow this user to:" and make sure everything is check EXCEPT "Show when being observed"; click "OK"; click "Continue"
  7. Check "Set request permission option: Allowed"; Check "Set VNC viewer access: Allowed"; click "Continue"
  8. Don't select any "Set field" options, just click "Continue"
  9. Select "Run this task from: This application"; click "Change"

Find users on remote machine with Apple Remote Desktop

List all the users (as long as the user names do not start with an underscore)

$ dscl . list /Users | grep -v "^_"

See if a specific user exists

$ dscl . list /Users | grep SPECIFIC_USER

Delete a user with Apple Remote Desktop

FIRST STEP: Delete the user account (run as root)

$ dscl . delete /Users/USER_TO_DELETE

SECOND STEP: Remove the deleted user's home directory (run as root)

$ rm -rf /Users/USER_TO_DELETE

THIRD STEP: Confirm / Set the Auto-Login user (see Auto-Login below....)

FOURTH STEP: Reboot the machine in case the user you just deleted was the logged-in user (run as root)

$ shutdown -r now

Software Updates

Check them..

$ softwareupdate --schedule

Disable them...

$ softwareupdate --schedule off

Hostname

Check them...

$ scutil --get HostName 
$ scutil --get LocalHostName
$ scutil --get ComputerName

Change them...

$ scutil --set HostName new_hostname
$ scutil --set LocalHostName new_hostname
$ scutil --set ComputerName new_hostname

Bluetooth

Disable (setting maintained even after reboot) -- requires reboot

10.7 and earlier
First turn off Bluetooth
$ defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState -bool NO
$ killall blued
Now prevent it from starting up on boot
$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.blued.plist
10.8 and later

Just make sure the Bluetooth services can't be found

$ sudo mkdir -p /System/Library/Extensions-Disabled
$ sudo mv /System/Library/Extensions/IOBluetooth* /System/Library/Extensions-Disabled/

Enable

10.7 and earlier
$ sudo launchctl load -wF /System/Library/LaunchDaemons/com.apple.blued.plist
10.8 and later
$ sudo mv /System/Library/Extensions-Disabled/* /System/Library/Extensions/

Wifi

Disable wifi

$ networksetup -setairportpower airport off

Enable wifi

$ networksetup -setairportpower airport on

Sleep

Check them..

$ systemsetup -getsleep 
$ systemsetup -getwakeonnetworkaccess

Change them...

$ systemsetup -setsleep Never
$ systemsetup -setdisplaysleep Never
$ systemsetup -setharddisksleep Never
$ systemsetup -setwakeonnetworkaccess on 

Power Issues (Note: not supported on laptops)

Check them...

$ systemsetup -getallowpowerbuttontosleepcomputer 
$ systemsetup -getrestartpowerfailure 

Change them...

$ systemsetup -setallowpowerbuttontosleepcomputer off
$ systemsetup -setrestartpowerfailure on    

Power Cycling (Auto shutdown / sleep / wake)

Check the current settings

$ pmset -g sched

Set up a recurring event format (note that this overwrites any previous repeating settings, so if you want a shutdown and a startup, you need to specify both of those within ONE pmset command [see EXAMPLE 3 below])

$ pmset repeat TYPE DAYS TIME
TYPE: sleep, wake, poweron, shutdown, or wakeorpoweron
DAYS: a subset of MTWRFSU
TIME: hh:mm:ss on a 24-hour clock

EXAMPLE 1: Power on everyday at 6am

$ pmset repeat wakeorpoweron MTWRFSU 06:00:00

EXAMPLE 2: Power off everyday at midnight

$ pmset repeat shutdown MTWRFSU 00:00:00

EXAMPLE 3: Power on everyday at 6am and power off everyday at midnight

$ pmset repeat shutdown MTWRFSU 00:00:00 wakeorpoweron MTWRFSU 05:00:00

Remove a repeating schedule

$ pmset repeat cancel

####To force shutdown (not allow applications to hang shutdown) set up a cron or launchd job:

####launchd: $ sudo vim /Library/LaunchAgents/me.adenine.forceshutdown.plist and paste in the following code to shutdown everyday at 11pm

<?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>me.adenine.forceshutdown</string>
    <key>ProgramArguments</key>
    <array>
        <string>shutdown</string>
        <string>-h</string>
        <string>now</string>

    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>23</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
</dict>
</plist>

make sure the file has root privileges:

$ sudo chown root /Library/LaunchAgents/me.adenine.forceshutdown.plist

and then load it into launchd:

$ sudo launchctl load /Library/LaunchAgents/me.adenine.forceshutdown.plist

####cron job: $ sudo crontab -e and append the following to the file:

00 23 * * * /sbin/shutdown -h now

force shutdown information gleaned from: http://apple.stackexchange.com/questions/25001/how-can-i-forcibly-shut-down-my-mac-at-an-appointed-time

Auto-Login

Check...

$ defaults read /Library/Preferences/com.apple.loginwindow

Set

$ defaults write /Library/Preferences/com.apple.loginwindow "autoLoginUser" "username"
This also requires the password for the autologin user to be obfuscated and stored in /private/etc/kcpassword. See the basecamp page for Mountain View for instructions on how to use the python script that was uploaded there for obfuscating the password.

Start-Up Items

Check...

$ osascript -e 'tell application "System Events" to get the name of every login item'

Add

$ osascript -e 'tell application "System Events" to make login item at end with properties {path:"/path/to/itemname", hidden:false}' 

Delete

$ osascript -e 'tell application "System Events" to delete login item "itemname"' 

Chrome Auto-Update

Turn off

$ defaults write com.google.Keystone.Agent checkInterval 0

Turn on

$ defaults write com.google.Keystone.Agent checkInterval 18000

Crash Reporting

Turn off

$ defaults write com.apple.CrashReporter DialogType none

Turn on

$ defaults write com.apple.CrashReporter DialogType crashreport

Disable Expose

Check if it is disabled

$ defaults read com.apple.dock mcx-expose-disabled

Disable it

$ defaults write com.apple.dock mcx-expose-disabled -bool true
$ killall Dock

Hide dock

Check it

$ defaults read com.apple.dock autohide

Set it

$ defaults write com.apple.dock autohide -bool YES
$ killall Dock

Disable dashboard

Check it

$ defaults read com.apple.dashboard mcx-disabled

Disable it

$ defaults write com.apple.dashboard mcx-disabled -boolean YES

Disable Screensavers

Check time setting

$ defaults -currentHost read com.apple.screensaver idleTime

Disable (Set to Never)

$ defaults -currentHost write com.apple.screensaver idleTime 0

Remote Login

Check

$ systemsetup -getremotelogin 

Turn on

$ systemsetup -setremotelogin on

Apple Remote Management

Check

$ systemsetup -getremoteappleevents 

Turn on

$ systemsetup -setremoteappleevents on

Turn off drives, servers, etc. from appearing on desktop

Check

$ defaults read com.apple.finder ShowHardDrivesOnDesktop
$ defaults read com.apple.finder ShowRemovableMediaOnDesktop
$ defaults read com.apple.finder ShowExternalHardDrivesOnDesktop

Make them hidden

$ defaults write com.apple.finder ShowHardDrivesOnDesktop -bool NO
$ defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool NO
$ defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool NO
$ killall Finder

Turn off Notification Center (OS X 10.8+)

Check

$ sudo defaults read /System/Library/LaunchAgents/com.apple.notificationcenterui

Disable

$ sudo defaults write /System/Library/LaunchAgents/com.apple.notificationcenterui KeepAlive -bool false
$ killall NotificationCenter
Restart to take effect
⚠️ **GitHub.com Fallback** ⚠️