Author: Geoff

  • 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"
  • Google Apps Script Document Creator

    This script logs a greeting, creates a new Google Document with a timestamped title, and appends sample text to it while logging the document URL

    Click to view script…
    function myTestScript() {
      // Log a simple greeting message
      Logger.log("Hello, Google Apps Script!");
    
      // Get and log the active user's email address
      var userEmail = Session.getActiveUser().getEmail();
      Logger.log("Active user: " + userEmail);
    
      // Create a new Google Document with a unique name based on the current date and time
      var doc = DocumentApp.create("Test Document " + new Date());
      var body = doc.getBody();
    
      // Append some paragraphs to the document
      body.appendParagraph("This document was created by a test script in Google Apps Script.");
      body.appendParagraph("Active user email: " + userEmail);
    
      // Log the URL of the created document so you can easily open it
      Logger.log("Document created: " + doc.getUrl());
    }
  • 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}"