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"