Create a gist now

Instantly share code, notes, and snippets.

@edenwaith /tss.sh
Last active Feb 3, 2017

Command line bash script to take a screenshot of the Xcode Simulator
#!/bin/sh
# TSS = Take Simulator Screenshot
# Script workaround for the crash in Xcode 8 Simulator crashing when
# trying to save a screenshot in El Capitan
# Version: 1.2 (3 February 2017) - Add screenshot to clipboard
# Version: 1.1 (31 January 2017) - Play screenshot file
# Version: 1.0 (Early January 2017) - Initial version
# Change to the Desktop, take the screenshot, then move back to the original directory
cd ~/Desktop
CWD=`pwd`
# Take the screenshot of the simulator
SCREENSHOT_OUTPUT=`xcrun simctl io booted screenshot`
# Grab the name of the screenshot file
SCREENSHOT_FILENAME=`echo "$SCREENSHOT_OUTPUT" | awk -F' ' '{print $NF}'`
# Create the full path for the screenshot
SCREENSHOT_FILEPATH="$CWD/$SCREENSHOT_FILENAME"
# Copy screenshot to the clipboard
if [ -e "$SCREENSHOT_FILEPATH" ]
then
osascript -e "set the clipboard to POSIX file \"$SCREENSHOT_FILEPATH\""
fi
# Play snapshot sound
GRAB_FILE="/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/Grab.aif"
if [ -e "$GRAB_FILE" ]
then
afplay "$GRAB_FILE"
fi
# Return to original directory
cd -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment