Skip to content

Instantly share code, notes, and snippets.

@edenwaith
Last active October 1, 2018 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edenwaith/ac77a9d8dc87c441d534c2dc3e4920d0 to your computer and use it in GitHub Desktop.
Save edenwaith/ac77a9d8dc87c441d534c2dc3e4920d0 to your computer and use it in GitHub Desktop.
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 -
@Eyesonly88
Copy link

xcrun simctl io booted screenshot screenshot.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment