Issue #1: Allow to run without sudo access.
This commit is contained in:
@@ -11,11 +11,15 @@
|
|||||||
# @author Jeff Geerling, 2014
|
# @author Jeff Geerling, 2014
|
||||||
# Based on .osx file from https://github.com/mathiasbynens/dotfiles.
|
# Based on .osx file from https://github.com/mathiasbynens/dotfiles.
|
||||||
|
|
||||||
# Get admin password for sudo
|
# Warn that some commands will not be run if the script is not run as root.
|
||||||
sudo -v
|
if [[ $EUID -ne 0 ]]; then
|
||||||
|
RUN_AS_ROOT=false
|
||||||
|
printf "Certain commands will not be run without sudo privileges. To run as root, run the same command prepended with 'sudo', for example: $ sudo $0\n\n" | fold -s -w 80
|
||||||
|
else
|
||||||
|
RUN_AS_ROOT=true
|
||||||
# Update existing `sudo` timestamp until `.osx` has finished
|
# Update existing `sudo` timestamp until `.osx` has finished
|
||||||
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
|
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
|
||||||
|
fi
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# General UI/UX #
|
# General UI/UX #
|
||||||
@@ -23,10 +27,14 @@ while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
|
|||||||
|
|
||||||
# Set standby delay to 24 hours (default is 1 hour)
|
# Set standby delay to 24 hours (default is 1 hour)
|
||||||
# You can check current values with `pmset -g`.
|
# You can check current values with `pmset -g`.
|
||||||
|
if [[ "$RUN_AS_ROOT" = true ]]; then
|
||||||
sudo pmset -a standbydelay 86400
|
sudo pmset -a standbydelay 86400
|
||||||
|
fi
|
||||||
|
|
||||||
# Disable system sleep (helpful if you're usually plugged into mains power).
|
# Disable system sleep (helpful if you're usually plugged into mains power).
|
||||||
|
if [[ "$RUN_AS_ROOT" = true ]]; then
|
||||||
sudo pmset -a sleep 0
|
sudo pmset -a sleep 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Expand save panel by default
|
# Expand save panel by default
|
||||||
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
|
defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true
|
||||||
@@ -42,10 +50,14 @@ defaults write com.apple.print.PrintingPrefs "Quit When Finished" -bool true
|
|||||||
|
|
||||||
# Reveal IP address, hostname, OS version, etc. when clicking the clock
|
# Reveal IP address, hostname, OS version, etc. when clicking the clock
|
||||||
# in the login window
|
# in the login window
|
||||||
|
if [[ "$RUN_AS_ROOT" = true ]]; then
|
||||||
sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName
|
sudo defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName
|
||||||
|
fi
|
||||||
|
|
||||||
# Restart automatically if the computer freezes
|
# Restart automatically if the computer freezes
|
||||||
|
if [[ "$RUN_AS_ROOT" = true ]]; then
|
||||||
systemsetup -setrestartfreeze on
|
systemsetup -setrestartfreeze on
|
||||||
|
fi
|
||||||
|
|
||||||
# Disable Notification Center and remove the menu bar icon
|
# Disable Notification Center and remove the menu bar icon
|
||||||
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null
|
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null
|
||||||
@@ -63,6 +75,7 @@ sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db "update data set v
|
|||||||
# SSD-specific tweaks #
|
# SSD-specific tweaks #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
if [[ "$RUN_AS_ROOT" = true ]]; then
|
||||||
# Disable local Time Machine snapshots
|
# Disable local Time Machine snapshots
|
||||||
sudo tmutil disablelocal
|
sudo tmutil disablelocal
|
||||||
|
|
||||||
@@ -78,6 +91,7 @@ sudo chflags uchg /Private/var/vm/sleepimage
|
|||||||
|
|
||||||
# Disable the sudden motion sensor as it’s not useful for SSDs
|
# Disable the sudden motion sensor as it’s not useful for SSDs
|
||||||
sudo pmset -a sms 0
|
sudo pmset -a sms 0
|
||||||
|
fi
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
|
# Trackpad, mouse, keyboard, Bluetooth accessories, and input #
|
||||||
@@ -133,7 +147,9 @@ defaults write com.apple.screencapture disable-shadow -bool true
|
|||||||
defaults write NSGlobalDomain AppleFontSmoothing -int 2
|
defaults write NSGlobalDomain AppleFontSmoothing -int 2
|
||||||
|
|
||||||
# Enable HiDPI display modes (requires restart)
|
# Enable HiDPI display modes (requires restart)
|
||||||
|
# if [[ "$RUN_AS_ROOT" = true ]]; then
|
||||||
# sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true
|
# sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true
|
||||||
|
# fi
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Finder #
|
# Finder #
|
||||||
@@ -217,7 +233,9 @@ defaults write com.apple.finder FXPreferredViewStyle -string "clmv"
|
|||||||
# defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true
|
# defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true
|
||||||
|
|
||||||
# Enable the MacBook Air SuperDrive on any Mac
|
# Enable the MacBook Air SuperDrive on any Mac
|
||||||
|
# if [[ "$RUN_AS_ROOT" = true ]]; then
|
||||||
# sudo nvram boot-args="mbasd=1"
|
# sudo nvram boot-args="mbasd=1"
|
||||||
|
# fi
|
||||||
|
|
||||||
# Show the ~/Library folder
|
# Show the ~/Library folder
|
||||||
chflags nohidden ~/Library
|
chflags nohidden ~/Library
|
||||||
@@ -278,7 +296,9 @@ defaults write com.apple.dock showhidden -bool true
|
|||||||
defaults write com.apple.universalaccess reduceTransparency -bool true
|
defaults write com.apple.universalaccess reduceTransparency -bool true
|
||||||
|
|
||||||
# Add iOS Simulator to Applications folder.
|
# Add iOS Simulator to Applications folder.
|
||||||
sudo ln -sf /Applications/Xcode.app/Contents/Applications/iPhone\ Simulator.app /Applications/iOS\ Simulator.app
|
if [[ "$RUN_AS_ROOT" = true ]]; then
|
||||||
|
sudo ln -sf /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app
|
||||||
|
fi
|
||||||
|
|
||||||
# Hot corners
|
# Hot corners
|
||||||
# Possible values:
|
# Possible values:
|
||||||
@@ -355,12 +375,15 @@ defaults write com.apple.mail DraftsViewerAttributes -dict-add "DisplayInThreade
|
|||||||
# Spotlight #
|
# Spotlight #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
if [[ "$RUN_AS_ROOT" = true ]]; then
|
||||||
# Disable Spotlight indexing for any volume that gets mounted and has not yet
|
# Disable Spotlight indexing for any volume that gets mounted and has not yet
|
||||||
# been indexed before.
|
# been indexed before.
|
||||||
# Use `sudo mdutil -i off "/Volumes/foo"` to stop indexing any volume.
|
# Use `sudo mdutil -i off "/Volumes/foo"` to stop indexing any volume.
|
||||||
sudo defaults write /.Spotlight-V100/VolumeConfiguration Exclusions -array "/Volumes"
|
sudo defaults write /.Spotlight-V100/VolumeConfiguration Exclusions -array "/Volumes"
|
||||||
|
|
||||||
# Restart spotlight
|
# Restart spotlight
|
||||||
killall mds > /dev/null 2>&1
|
killall mds > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Terminal #
|
# Terminal #
|
||||||
@@ -419,4 +442,5 @@ defaults write com.apple.messageshelper.MessageController SOInputLineSettings -d
|
|||||||
for app in "cfprefsd" "Dock" "Finder" "Mail" "SystemUIServer" "Terminal"; do
|
for app in "cfprefsd" "Dock" "Finder" "Mail" "SystemUIServer" "Terminal"; do
|
||||||
killall "${app}" > /dev/null 2>&1
|
killall "${app}" > /dev/null 2>&1
|
||||||
done
|
done
|
||||||
echo "Please log out and log back in to make all settings take effect."
|
|
||||||
|
printf "Please log out and log back in to make all settings take effect.\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user