Last active
October 1, 2018 04:15
-
-
Save edenwaith/ac77a9d8dc87c441d534c2dc3e4920d0 to your computer and use it in GitHub Desktop.
Command line bash script to take a screenshot of the Xcode Simulator
This file contains 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
#!/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
xcrun simctl io booted screenshot screenshot.png