#!/bin/bash

# Hide Terminal and close finder windows
/usr/bin/osascript -e 'tell application "Finder" to set visible of process "Terminal" to false'
/usr/bin/osascript -e 'tell application "Finder" to close every window'


# Create user LaunchAgents directory if one doesn't exist 
if [ ! -d ~/Library/LaunchAgents ]; then
	mkdir ~/Library/LaunchAgents
fi

# Set screen saver and start it after 2 minutes of inactivity
defaults write ~/Library/Preferences/ByHost/com.apple.screensaver moduleDict -dict moduleName -string "Computer Name" path -string "/System/Library/Frameworks/ScreenSaver.framework/Resources/Computer Name.saver" type -int "0"
defaults write ~/Library/Preferences/ByHost/com.apple.screensaver idleTime 120
# This one has capital S
defaults write ~/Library/Preferences/ByHost/com.apple.ScreenSaver.Basic MESSAGE "I'm a meaningful and valued member of this team. NOT"

# Set volume to medium
/usr/bin/osascript -e "set volume 4"

# Setup LaunchAgent
/usr/bin/tail -n 15 "$0" > ~/Library/LaunchAgents/lockyourmachine.plist
/bin/chmod 644 ~/Library/LaunchAgents/lockyourmachine.plist
/bin/launchctl load ~/Library/LaunchAgents/lockyourmachine.plist

# Set safari home page to Rickroll, won't kick in until next time safari is launched ... nice :)
defaults write com.apple.safari.plist HomePage "https://youtu.be/oHg5SJYRHA0?t=44"


# swap mouse button config, won't kick in until next login ... ah the script that just keeps giving :)
defaults -currentHost write .GlobalPreferences com.apple.mouse.swapLeftRightButton -bool true


# take a screen shot and set it as desktop image
screencapture /Users/Shared/screen.jpeg
/usr/bin/osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Users/Shared/screen.jpeg"'
defaults write com.apple.dock autohide -bool yes
killall Dock


# Do Not show "Mounted Server Shares, External and Internal Hard Disks" on the main Finder Desktop
defaults write com.apple.finder ShowMountedServersOnDesktop -bool false
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool false
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool false
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool false
killall Finder && open /System/Library/CoreServices/Finder.app

# Move all desktop icons
if [ ! -d ~/DesktopOLD ]; then
	mkdir ~/DesktopOLD
fi
mv ~/Desktop/* ~/DesktopOLD/



exit



<?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>lockyourmachine</string>
			<key>ProgramArguments</key>
			<array>
				<string>/usr/bin/say</string>
				<string>"You should lock your Machine ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, You're a very naughty boy"</string>
			</array>
			<key>StartInterval</key>
			<integer>300</integer>
	</dict>
</plist>