Category: macOS

  • Light and Dark Mode Toggler AppleScript

    This AppleScript toggles your macOS display between dark and light modes, letting you quickly adapt your favorite setting.

    Click to view script…
    tell application "System Events"
        tell appearance preferences
            set dark mode to not dark mode
        end tell
    end tell

  • Mac System Specs and Performance Dashboard Bash Script

    This script provides an organized summary of your Mac’s system information and performance metrics—including OS details, CPU specifications, memory size, disk usage, uptime, and battery status.

    Click to view script…
    #!/bin/bash
    # system_specs.sh - Display Mac system specs and performance info
    
    # Clear the terminal for a fresh display
    clear
    
    echo "======================================"
    echo "   Mac System Specs and Performance   "
    echo "======================================"
    
    # Operating System Information
    os_name=$(sw_vers -productName)
    os_version=$(sw_vers -productVersion)
    build_version=$(sw_vers -buildVersion)
    echo "Operating System: $os_name $os_version (Build $build_version)"
    
    # Computer Name (if set)
    computer_name=$(scutil --get ComputerName 2>/dev/null)
    if [ -n "$computer_name" ]; then
        echo "Computer Name: $computer_name"
    fi
    
    echo "--------------------------------------"
    
    # CPU Information
    cpu_brand=$(sysctl -n machdep.cpu.brand_string)
    physical_cpu=$(sysctl -n hw.physicalcpu)
    logical_cpu=$(sysctl -n hw.logicalcpu)
    echo "CPU: $cpu_brand"
    echo "Physical Cores: $physical_cpu"
    echo "Logical Cores: $logical_cpu"
    
    echo "--------------------------------------"
    
    # Memory (RAM) Information
    mem_bytes=$(sysctl -n hw.memsize)
    # Convert bytes to gigabytes (1GB = 1073741824 bytes)
    mem_gb=$(echo "scale=2; $mem_bytes/1073741824" | bc)
    echo "Memory (RAM): $mem_gb GB"
    
    echo "--------------------------------------"
    
    # Disk Usage for the Root Partition
    echo "Disk Usage (Root Partition):"
    # Display header and the line for '/' partition
    df -h / | awk 'NR==1 || $NF=="/"'
    echo "--------------------------------------"
    
    # Uptime and Load Average
    echo "Uptime and Load Average:"
    uptime
    echo "--------------------------------------"
    
    # Battery Information (if available)
    if command -v pmset &> /dev/null; then
        battery_info=$(pmset -g batt | head -1)
        echo "Battery Info: $battery_info"
    fi
    
    echo "======================================"
  • Dynamic Folder Generator on macOS with AppleScript

    This AppleScript streamlines folder creation by prompting users for the number of folders, a base name, and a destination location. It then automatically creates sequentially numbered folders in the chosen directory, simplifying organization and file management on macOS.

    Click to view script…
    -- Ask the user how many folders they want to create
    set folderCountString to text returned of (display dialog "How many folders do you want to create?" default answer "1")
    try
        set folderCount to folderCountString as integer
    on error
        display dialog "Please enter a valid number."
        return
    end try
    
    -- Ask for a base name for the folders
    set baseName to text returned of (display dialog "Enter a base name for your folders:" default answer "Folder")
    
    -- Let the user choose the target location (e.g., Desktop, Documents, Downloads, etc.)
    set targetFolder to choose folder with prompt "Choose the folder where the new folders will be created:"
    
    -- Create the folders
    tell application "Finder"
        repeat with i from 1 to folderCount
            set folderName to baseName & " " & i
            try
                make new folder at targetFolder with properties {name:folderName}
            on error errMsg number errNum
                display dialog "Error creating folder \"" & folderName & "\": " & errMsg
            end try
        end repeat
    end tell
    
    display dialog "Successfully created " & folderCount & " folder(s) in " & (targetFolder as text)
  • Simple Scheduled Website Opener AppleScript

    This AppleScript prompts you to enter a delay in seconds and a website URL, then opens the specified website in your default browser after the delay. A confirmation dialog informs you that the site will launch after you close it, making it a straightforward scheduling tool for web access.

    Click to view script…
    -- Simple Scheduled Website Opener
    -- Prompts the user for a delay (in seconds) and a website URL, then opens the URL after the delay.
    
    -- Ask the user for the delay in seconds
    set delayResponse to display dialog "Enter the number of seconds to wait before opening the website:" default answer "10"
    set delaySeconds to (text returned of delayResponse) as number
    
    -- Ask the user for the website URL
    set urlResponse to display dialog "Enter the website URL to open:" default answer "https://"
    set websiteURL to text returned of urlResponse
    
    -- Confirmation dialog informing the website will open after the dialog is closed
    display dialog "The website " & websiteURL & " will open in " & delaySeconds & " seconds after you close this dialog." buttons {"Cancel", "OK"} default button "OK"
    if button returned of result is "Cancel" then return
    
    -- Wait for the specified delay
    delay delaySeconds
    
    -- Open the website in the default browser
    do shell script "open " & quoted form of websiteURL

  • Rickroll Launcher AppleScript

    This AppleScript command uses a shell command to open a popular YouTube video in your default browser, effectively “Rickrolling” the user. It’s a playful example of how to execute shell scripts from within AppleScript.

    Click to view script…
    do shell script "open https://www.youtube.com/watch?v=dQw4w9WgXcQ"
  • Simulating a macOS Crash Using AppleScript

    This AppleScript launches the macOS screensaver to create the appearance of an unresponsive system, then plays a voice message saying, “Uh oh. Something went wrong.” The combination can be used for testing reactions or demonstrating AppleScript’s ability to control system functions.

    Click to view script…
    do shell script "open /System/Library/CoreServices/ScreenSaverEngine.app"
    delay 2
    say "Uh oh. Something went wrong."

  • Gather Weather Bash Script

    This Bash script uses the wttr.in service to automatically fetch and display your current weather based on your IP geolocation, directly in your macOS terminal. It first checks for the curl utility and then outputs the ASCII weather forecast

    Click to view script…
    #!/bin/bash
    # current_weather.sh - Query current weather for your current location on macOS.
    # This script uses the wttr.in API to retrieve weather information based on your IP geolocation.
    # Usage: ./current_weather.sh
    
    # Define colors for output
    BLUE='\033[0;34m'
    NC='\033[0m'  # No Color
    
    # Ensure curl is installed
    if ! command -v curl &>/dev/null; then
      echo "Error: curl is not installed. Please install curl to use this script."
      exit 1
    fi
    
    echo -e "${BLUE}Fetching current weather for your location...${NC}"
    weather=$(curl -s wttr.in)
    
    if [ -z "$weather" ]; then
      echo "Error: Unable to retrieve weather information."
      exit 1
    fi
    
    echo "$weather"
  • macOS Public IP Checker Bash Script

    This Bash script uses curl to query ifconfig.me for your public IP address and then displays it in the Terminal on macOS.

    Click to view script…
    #!/bin/bash
    # check_public_ip.command - Display your public IP address on macOS
    # This script uses curl to query ifconfig.me, which returns your public IP address.
    # Usage: ./check_public_ip.command
    
    # Check if curl is installed
    if ! command -v curl &>/dev/null; then
      echo "Error: curl is not installed. Please install curl to use this script."
      exit 1
    fi
    
    echo "Fetching public IP address..."
    public_ip=$(curl -s ifconfig.me)
    
    if [ -z "$public_ip" ]; then
      echo "Error: Unable to retrieve public IP address."
      exit 1
    fi
    
    echo "Your public IP address is: $public_ip"
  • macOS Network Diagnostics & Information Tool Bash Script

    This Bash script collects detailed network information on a macOS system by querying system utilities (like routeifconfig, and ipconfig) and formatting the output with colored text for easy reading. It reports data such as the default gateway, active interface, IP address, subnet mask, broadcast address, MAC address, DNS servers, public IP, and average ping latency

    Click to view script…
    #!/bin/bash
    # netinfo_detailed.sh - Detailed network information for macOS
    
    # Define colors for output (ANSI escape codes)
    RED='\033[0;31m'
    GREEN='\033[0;32m'
    BLUE='\033[0;34m'
    NC='\033[0m' # No Color
    
    echo -e "${BLUE}Gathering default route information...${NC}"
    
    # Get the default gateway and active interface from the routing table.
    default_route=$(route -n get default 2>/dev/null)
    gateway=$(echo "$default_route" | awk '/gateway/ {print $2}')
    iface=$(echo "$default_route" | awk '/interface/ {print $2}')
    
    if [ -z "$iface" ]; then
      echo -e "${RED}Error: No active network interface found. Are you connected to a network?${NC}"
      exit 1
    fi
    
    echo -e "${GREEN}Default Interface: ${NC}$iface"
    echo -e "${GREEN}Gateway: ${NC}$gateway"
    
    # Get the IP address for the active interface.
    ip=$(ipconfig getifaddr "$iface")
    echo -e "${GREEN}IP Address: ${NC}$ip"
    
    # Retrieve the subnet mask in hexadecimal from ifconfig.
    # Expected format is like: "inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255"
    mask_hex=$(ifconfig "$iface" | awk '/inet / {print $4}')
    # Remove any leading "0x" using sed so that we have exactly 8 hex digits.
    mask_hex=$(echo "$mask_hex" | sed 's/^0x//')
    if [ ${#mask_hex} -ne 8 ]; then
      echo -e "${RED}Unexpected netmask format: $mask_hex${NC}"
      netmask="Unknown"
    else
      mask1=$((16#${mask_hex:0:2}))
      mask2=$((16#${mask_hex:2:2}))
      mask3=$((16#${mask_hex:4:2}))
      mask4=$((16#${mask_hex:6:2}))
      netmask="${mask1}.${mask2}.${mask3}.${mask4}"
    fi
    echo -e "${GREEN}Subnet Mask: ${NC}$netmask"
    
    # Get the broadcast address from ifconfig output.
    broadcast=$(ifconfig "$iface" | awk '/broadcast/ {print $4}')
    echo -e "${GREEN}Broadcast Address: ${NC}$broadcast"
    
    # Get the MAC (hardware) address of the interface.
    mac=$(ifconfig "$iface" | awk '/ether/ {print $2}')
    echo -e "${GREEN}MAC Address: ${NC}$mac"
    
    # Retrieve DNS servers from /etc/resolv.conf.
    dns_servers=$(grep 'nameserver' /etc/resolv.conf | awk '{print $2}' | tr '\n' ' ')
    echo -e "${GREEN}DNS Servers: ${NC}$dns_servers"
    
    # Get the public IP address using an external service.
    public_ip=$(curl -s ifconfig.me)
    echo -e "${GREEN}Public IP Address: ${NC}$public_ip"
    
    # Perform a ping test to google.com and extract the average latency.
    echo -e "${BLUE}Performing ping test to google.com...${NC}"
    ping_result=$(ping -c 3 google.com 2>/dev/null)
    avg_rtt=$(echo "$ping_result" | tail -1 | awk -F'/' '{print $5}')
    if [ -n "$avg_rtt" ]; then
      echo -e "${GREEN}Average Latency (ping): ${NC}${avg_rtt} ms"
    else
      echo -e "${RED}Ping test failed.${NC}"
    fi
    
    echo -e "${BLUE}Detailed network information gathered successfully.${NC}"