Skip to content

Instantly share code, notes, and snippets.

@justinhartman
Created May 6, 2020 00:03
Show Gist options
  • Save justinhartman/8ee7623d60839810010ae3420d8fb055 to your computer and use it in GitHub Desktop.
Save justinhartman/8ee7623d60839810010ae3420d8fb055 to your computer and use it in GitHub Desktop.
Take fullscreen screenshots using Firefox and Bash
#!/usr/bin/env bash
#
# Take fullscreen screenshots using Firefox.
#
# Author: Justin Hartman <justin@hartman.me>
# Version: 1.0.0
# Copyright (c) 2020 Justin Hartman <https://hartman.me>
#
#######################################
# Defines set of gloval variables.
# Globals:
# None
# Arguments:
# String Accepts url to website.
# Returns:
# None
#######################################
globals () {
dir='/Users/justin/Google Drive/Google Drive/Images/Screenshots/Full Screen'
fox='/Applications/Firefox.app/Contents/MacOS/firefox'
file=$(date +"%Y-%m-%d_%H.%M.%S.png")
url=$1
export dir fox file url
}
#######################################
# Navigate to the screenshot folder.
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#######################################
paths() {
echo -e '📂 Navigating to screenshot directory.'
cd "${dir}" || exit
}
#######################################
# Take screenshot using FF.
# Globals:
# None
# Arguments:
# None
# Returns:
# None
#######################################
screen() {
echo "📸 Taking screenshot for: ${url}"
"${fox}" --screenshot "${file}" "${url}"
}
# Load the global variables.
globals "$@"
# Check if the path to Firefox is correct.
if [[ -f "${fox}" ]]; then
# Determine if we need the URL input or not.
if [[ $# -eq 0 ]]; then
read -rp "🔗 Enter the URL of the website: " url
fi
# Run the methods.
paths
screen
# Exit gracefully.
echo "🏁 Saved screenshot as: ${file}"
exit 0
else
echo -e '------------------------------------------------------------------'
echo -e 'Cannot find your Firefox binary at the following path:'
echo -e "${fox}\n"
echo -e 'Please update the path to Firefox in this script in order to fix'
echo -e 'the issue and then try run this command again.'
echo -e '------------------------------------------------------------------'
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment