Mac optimzation code.

Mac optimzation code.

echo “πŸš€ Starting the ultimate macOS setup script with all requested features…”

--------------------------------------

πŸ”‘ Enable Passwordless Sudo

--------------------------------------

echo “πŸ”‘ Enabling passwordless sudo for the current user…”
USER=$(whoami)
SUDOERS_FILE=”/etc/sudoers.d/$USER”

if [ ! -f “$SUDOERS_FILE” ]; then
echo “$USER ALL=(ALL) NOPASSWD: ALL” | sudo tee “$SUDOERS_FILE” >/dev/null
sudo chmod 0440 “$SUDOERS_FILE”
echo “βœ… Passwordless sudo enabled for $USER!”
else
echo “βœ… Passwordless sudo is already configured for $USER!”
fi

Extend sudo timeout to 60 minutes

echo “Defaults timestamp_timeout=60” | sudo tee /etc/sudoers.d/timestamp_timeout >/dev/null
echo “⏲️ Sudo timeout extended to 60 minutes!”

--------------------------------------

πŸ“₯ Install Homebrew (if not installed)

--------------------------------------

echo “πŸ”„ Checking Homebrew installation…”
if [[ ! -f /opt/homebrew/bin/brew ]]; then
echo “⚠️ Homebrew is missing! Installing Homebrew…”
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)” || {
echo “❌ Failed to install Homebrew. Exiting…”
exit 1
}
else
echo “βœ… Homebrew is already installed!”
fi
export PATH=”/opt/homebrew/bin:$PATH”

--------------------------------------

πŸ“₯ Install Zenity

--------------------------------------

echo “πŸ“₯ Installing Zenity for interactive dialogs…”
if ! brew list zenity &>/dev/null; then
brew install zenity || {
echo “❌ Failed to install Zenity. Continuing…”
}
else
echo “βœ… Zenity is already installed!”
fi

--------------------------------------

πŸ“Ί Install VLC, Google Chrome, and Termius

--------------------------------------

echo “πŸ“Ί Installing VLC, Google Chrome, and Termius…”
for app in vlc google-chrome termius; do
if ! brew list –cask “$app” &>/dev/null; then
brew install –cask “$app” || {
echo “❌ Failed to install $app. Continuing…”
}
else
echo “βœ… $app is already installed!”
fi
done

--------------------------------------

πŸ”‘ Enable Find My Mac

--------------------------------------

echo “πŸ” Enabling Find My Mac…”
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locationd.plist
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.findmymac.plist
echo “βœ… Find My Mac enabled!”

--------------------------------------

πŸ’¬ Enable iMessage

--------------------------------------

echo “πŸ’¬ Enabling iMessage…”
defaults write com.apple.messageshelper.AccountInfoController Enabled -bool true
echo “βœ… iMessage enabled! Please sign in manually to complete setup.”

--------------------------------------

⌚ Enable Unlock with Apple Watch

--------------------------------------

echo “⌚ Enabling Unlock with Apple Watch…”
defaults write com.apple.controlcenter “NSStatusItem Visible UnlockWithWatch” -bool true
echo “βœ… Unlock with Apple Watch enabled! Ensure your devices are paired and signed into the same iCloud account.”

--------------------------------------

πŸ”„ Enable Universal Control

--------------------------------------

echo “πŸ”„ Enabling Universal Control…”
defaults write com.apple.universalaccess “UniversalControlAllowCursorKeyboard” -bool true
defaults write com.apple.universalaccess “UniversalControlEdgeConnection” -bool true
defaults write com.apple.universalaccess “UniversalControlMultideviceConnection” -bool true
defaults write com.apple.sidecar.display “DisplayStatusMode” -string “always”
killall System\ Preferences
echo “βœ… Universal Control fully enabled!”

echo “πŸ”— To link your keyboard and mouse to other Macs using Universal Control:”
echo “1. Open System Settings on all Macs.”
echo “2. Go to ‘Displays’.”
echo “3. Click on ‘Add Display’ and select the other Mac.”
echo “4. Arrange the displays as needed.”
echo “5. Ensure ‘Allow your pointer and keyboard to move between any nearby Mac or iPad’ is enabled.”
echo “6. Check ‘Push through the edge of a display to connect to a nearby Mac or iPad’.”
echo “⚠️ This step must be done manually for security reasons.”

--------------------------------------

πŸ”Š Enable Bluetooth

--------------------------------------

echo “πŸ”Š Enabling Bluetooth…”
sudo defaults write /Library/Preferences/com.apple.Bluetooth ControllerPowerState -int 1
sudo killall bluetoothd
echo “βœ… Bluetooth enabled!”

--------------------------------------

πŸš€ Increase CPU Performance

--------------------------------------

echo “πŸš€ Enabling High Performance Mode…”
sudo pmset -a hibernatemode 0
sudo pmset -a standby 0
sudo pmset -a autopoweroff 0
sudo pmset -a displaysleep 0
sudo pmset -a sleep 0
sudo pmset -a powernap 0
echo “βœ… High performance settings applied!”

--------------------------------------

🟣 Set Background to Purple

--------------------------------------

echo “🟣 Setting desktop background to purple…”
osascript -e ‘tell application “System Events” to set picture of every desktop to (POSIX file “/System/Library/Desktop Pictures/Solid Colors/Purple 1.png”)’
echo “βœ… Desktop background changed to purple!”

--------------------------------------

πŸ”„ Reset and Customize Dock

--------------------------------------

echo “πŸ”„ Resetting and Customizing Dock…”
defaults delete com.apple.dock persistent-apps
defaults delete com.apple.dock persistent-others
defaults write com.apple.dock tilesize -int 36
defaults write com.apple.dock autohide -bool false
defaults write com.apple.dock show-recents -bool false
killall Dock
echo “βœ… Dock customized!”

--------------------------------------

πŸ” Verification of All Components

--------------------------------------

echo “πŸ” Verifying all installed components…”
echo “Google Chrome installed: $(brew list –cask | grep google-chrome)”
echo “Termius installed: $(brew list –cask | grep termius)”
echo “VLC installed: $(brew list –cask | grep vlc)”
echo “Bluetooth status: $(system_profiler SPBluetoothDataType | grep ‘State: On’)”
echo “Find My Mac enabled: $(sudo defaults read /Library/Preferences/com.apple.FindMyMac.plist)”
echo “Universal Control enabled: $(defaults read com.apple.universalaccess UniversalControlAllowCursorKeyboard)”

echo “πŸš€ Script completed successfully with all features verified!”

!/bin/bash

!/bin/bash

πŸš€ macOS Optimization Script with Full Cloud Sync, Progress Display in Zenity, and File Streaming

echo “πŸš€ Starting macOS Optimization…”

βœ… Logging function

log() { echo -e “\033[0;32m[βœ”] $1\033[0m”; }
error() { echo -e “\033[0;31m[❌] $1\033[0m”; exit 1; }

βœ… Ensure the script is run as root

if [[ $EUID -ne 0 ]]; then
error “⚠️ Please run this script as root using sudo”
fi

βœ… Enable iCloud Optimized Storage (Offload Unused Files)

enable_icloud_optimization() {
log “☁️ Enabling iCloud Optimized Storage…”
sudo defaults write ~/Library/Preferences/com.apple.bird optimizeStorage -bool true
killall bird
log “βœ… iCloud Optimized Storage Enabled!”
}

βœ… Configure Google Drive to Stream Files

setup_google_drive_streaming() {
log “πŸ”„ Setting Google Drive to Stream Mode…”
open -a “Google Drive”
log “βœ… Ensure Google Drive is set to ‘Stream files’ mode in Preferences!”
}

βœ… Sync All Files and Show Progress in Zenity

sync_files() {
log “πŸ”„ Starting Full Sync of iCloud Drive and Google Drive…”
SYNC_SOURCE=~/
ICLOUD_DEST=~/Library/Mobile\ Documents/com~apple~CloudDocs/
GOOGLE_DRIVE_DEST=~/GoogleDrive/

(rsync -av --progress "$SYNC_SOURCE" "$ICLOUD_DEST" | tee /tmp/icloud_sync.log) | zenity --progress --title="Syncing to iCloud Drive" --text="Syncing files..." --pulsate --auto-close --width=400
(rsync -av --progress "$SYNC_SOURCE" "$GOOGLE_DRIVE_DEST" | tee /tmp/google_drive_sync.log) | zenity --progress --title="Syncing to Google Drive" --text="Syncing files..." --pulsate --auto-close --width=400

log "βœ… Full Sync Completed!"

}

βœ… List Available Files for Download (Not Stored Locally)

list_cloud_files() {
log “πŸ“‚ Listing available files in iCloud and Google Drive…”
find ~/Library/Mobile\ Documents/com~apple~CloudDocs/ -type f > /tmp/icloud_files.txt
find ~/GoogleDrive/ -type f >> /tmp/google_drive_files.txt
cat /tmp/icloud_files.txt /tmp/google_drive_files.txt > /tmp/all_cloud_files.txt
zenity –list –title=”Cloud Files” –text=”Select a file to download” –column=”File” –filename=/tmp/all_cloud_files.txt –width=600 –height=400
}

βœ… Download Selected File from Cloud

download_file() {
FILE=$(zenity –file-selection –title=”Select file to download”)
if [ -f “$FILE” ]; then
log “⬇️ Downloading $FILE…”
open “$FILE”
log “βœ… File downloaded successfully!”
else
error “❌ File not found in cloud storage!”
fi
}

βœ… Run Selected Features

task_list=(“enable_icloud_optimization” “setup_google_drive_streaming” “sync_files” “list_cloud_files” “download_file”)
for task in “${task_list[@]}”; do
$task &
done

log “πŸŽ‰ All Tasks Completed Successfully!”

!/bin/bash

echo “πŸ”§ Forcing All macOS Apps to Think They Are Running on a 4K Display (Permanent Fix)…”

βœ… Enable HiDPI Mode for Retina-Like Scaling on 1920x1080

echo “πŸ–₯ Enabling HiDPI Scaling…”
sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true
sudo defaults write /Library/Preferences/com.apple.windowserver.plist DisplayHiDPIEnabled -bool true
sudo defaults write /Library/Preferences/com.apple.windowserver ExternalDisplayHIDPIEnabled -bool true

βœ… Trick macOS intoΓ₯ Reporting a 4K Display (Without Modifying App Info.plist)

echo “πŸ–₯ Setting macOS to Report a 4K Display (3840x2160)…”
sudo defaults write /Library/Preferences/com.apple.windowserver.plist DisplayResolutionWidth -int 3840
sudo defaults write /Library/Preferences/com.apple.windowserver.plist DisplayResolutionHeight -int 2160

βœ… Reduce UI Scaling for a Compact 4K-Like Experience

echo “πŸ“ Making macOS UI Smaller…”
defaults write -g AppleGlobalTextScalingFactor -float 0.35 # Shrinks UI system-wide

βœ… Make Fonts Smaller for More Screen Space

echo “πŸ”€ Reducing System Font Size…”
defaults write -g AppleFontSmoothing -int 1 # Lighter font smoothing for sharp edges
defaults write -g CGFontRenderingFontSmoothingDisabled -bool NO # Ensure clear text
defaults write -g NSFontSize -int 9 # Smallest readable font size

βœ… Reduce Finder Sidebar & Icons for a Compact UI

echo “πŸ“‚ Making Finder Compact…”
defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 1
defaults write com.apple.finder FXPreferredViewStyle -string “Nlsv”
defaults write com.apple.finder StandardViewSettings -dict-add “IconSize” -int 10

βœ… Shrink Dock to Free Up Space

echo “πŸ“ Making Dock Ultra-Compact…”
defaults write com.apple.dock tilesize -int 10
defaults write com.apple.dock autohide -bool true

βœ… Reduce Transparency for a Sharper UI

echo “πŸ–₯ Disabling Transparency for a Crisper Display…”
defaults write com.apple.universalaccess reduceTransparency -bool true

βœ… Force Full RGB Mode for External Displays (Fix Blurry Text & Colors)

echo “🎨 Enforcing Full RGB Mode…”
defaults write -g AppleFontSmoothing -int 1

βœ… Reduce Window Shadows for a Cleaner Look

echo “🎭 Removing Window Shadows…”
defaults write com.apple.universalaccess reduceMotion -bool true

βœ… Interactive GUI Selection

CHOICES=$(zenity –list –title “macOS 4K Optimization” –text “Select Features to Apply” –checklist –column “Select” –column “Feature” \
TRUE “Enable HiDPI Scaling” \
TRUE “Set macOS to Report 4K Display” \
TRUE “Reduce UI Scaling” \
TRUE “Reduce Font Size” \
TRUE “Compact Finder UI” \
TRUE “Shrink Dock” \
TRUE “Disable Transparency” \
TRUE “Enforce Full RGB Mode” \
TRUE “Reduce Window Shadows” \
–separator=”:” 2>/dev/null)

βœ… Process User Choices

IFS=”:” read -ra SELECTED <<< “$CHOICES”
for CHOICE in “${SELECTED[@]}”; do
case “$CHOICE” in
“Enable HiDPI Scaling”)
sudo defaults write /Library/Preferences/com.apple.windowserver DisplayResolutionEnabled -bool true
sudo defaults write /Library/Preferences/com.apple.windowserver.plist DisplayHiDPIEnabled -bool true
sudo defaults write /Library/Preferences/com.apple.windowserver ExternalDisplayHIDPIEnabled -bool true
;;
“Set macOS to Report 4K Display”)
sudo defaults write /Library/Preferences/com.apple.windowserver.plist DisplayResolutionWidth -int 3840
sudo defaults write /Library/Preferences/com.apple.windowserver.plist DisplayResolutionHeight -int 2160
;;
“Reduce UI Scaling”)
defaults write -g AppleGlobalTextScalingFactor -float 0.35
;;
“Reduce Font Size”)
defaults write -g AppleFontSmoothing -int 1
defaults write -g CGFontRenderingFontSmoothingDisabled -bool NO
defaults write -g NSFontSize -int 9
;;
“Compact Finder UI”)
defaults write NSGlobalDomain NSTableViewDefaultSizeMode -int 1
defaults write com.apple.finder FXPreferredViewStyle -string “Nlsv”
defaults write com.apple.finder StandardViewSettings -dict-add “IconSize” -int 10
;;
“Shrink Dock”)
defaults write com.apple.dock tilesize -int 10
defaults write com.apple.dock autohide -bool true
;;
“Disable Transparency”)
defaults write com.apple.universalaccess reduceTransparency -bool true
;;
“Enforce Full RGB Mode”)
defaults write -g AppleFontSmoothing -int 1
;;
“Reduce Window Shadows”)
defaults write com.apple.universalaccess reduceMotion -bool true
;;
esac
done

βœ… Restart macOS UI to Apply Changes

echo “πŸ”„ Restarting macOS UI Services…”
killall Finder && killall Dock && killall SystemUIServer

echo “βœ… macOS UI Now Optimized for 4K Scaling on 1920x1080 HiDPI!”

Back to Journal Edit