Tag: #Utility

  • 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

  • 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}"