Created
May 6, 2020 00:03
-
-
Save justinhartman/8ee7623d60839810010ae3420d8fb055 to your computer and use it in GitHub Desktop.
Take fullscreen screenshots using Firefox and Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Take fullscreen screenshots using Firefox. | |
# | |
# Author: Justin Hartman <[email protected]> | |
# 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