Last active
May 14, 2023 13:10
-
-
Save bhumit070/5801c253d6de3206d39152e95dac64f2 to your computer and use it in GitHub Desktop.
macos_screen_shot_script.sh
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
#!/bin/bash | |
randomScreenShotName="$RANDOM.png" | |
screenShotPath="/tmp/$randomScreenShotName" | |
screencapture $screenShotPath | |
screenShotDir="$HOME/screenshots/$(date +"%Y-%m-%d")" | |
if ! [ -d $screenShotDir ]; then | |
mkdir -p $screenShotDir | |
fi | |
takeScreenShotButton="Take ScreenShot" | |
takeScreenShotAndOpenPreviewButton="Take ScreenShot And Open Preview" | |
osaScript="osascript -e 'display dialog \"Enter name for screenshot:\" default answer \"\" buttons {\"$takeScreenShotButton\", \"$takeScreenShotAndOpenPreviewButton\"} default button 2'" | |
name=$(eval $osaScript) | |
screenshotName=$(echo $name | cut -d ":" -f 3 | xargs) | |
buttonName=$(echo $name | cut -d ":" -f 2 | cut -d "," -f 1 | xargs) | |
timestamp="$(date +"%T.%S")"; | |
if [ -z "$screenshotName" ] | |
then | |
screenshotName="$timestamp-$RANDOM.png" | |
else | |
screenshotName="$screenshotName-$timestamp.png" | |
fi | |
mv $screenShotPath "$screenShotDir/$screenshotName" | |
if [ "$buttonName" = "$takeScreenShotButton" ] | |
then | |
exit 0 | |
fi | |
open -n -a Preview "$screenShotDir/$screenshotName" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment