Last active
August 29, 2015 14:14
-
-
Save 844196/13f415083464815d59c4 to your computer and use it in GitHub Desktop.
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 | |
| # | |
| # @(#) スクショを撮影してタイトルバーとかをトリミングしてくれるやつ | |
| # | |
| # Author: | |
| # 844196 (@84____) | |
| # | |
| # License: | |
| # MIT | |
| # | |
| # initialize | |
| ## option | |
| set -u | |
| set -e | |
| ## about me | |
| readonly ME="${0##*/}" | |
| readonly VERSION="0.1" | |
| ## error | |
| function error() { | |
| echo "${ME}: ${1}" 1>&2 | |
| exit "${2:-1}" | |
| } | |
| ## temporary | |
| readonly TMPDIR="${TMP:-/tmp}/${ME}.$$" | |
| mkdir -p "${TMPDIR}" | |
| trap 'rm -r ${TMPDIR}' 0 | |
| function makeTmpFile() { | |
| local filename="${TMPDIR}/${1:-${RANDOM}.tmp}" | |
| ( | |
| umask 0077 | |
| : >"${filename}" | |
| ) && echo "${filename}" | |
| return 0 | |
| } | |
| ## check require command | |
| type convert >/dev/null 2>&1 || error "requires convert(ImageMagick)" "2" | |
| # main | |
| ## take screen capture | |
| screencapture -wo "$(makeTmpFile ss_master.png)" | |
| output_filename="${1:-./$(date +"%Y-%m-%d_%H-%M-%S").png}" | |
| ## triming top titlebar | |
| convert -chop 0x18 "${TMPDIR}/ss_master.png" "$(makeTmpFile ss_top-triming.png)" | |
| ## triming bottom round transpacy | |
| convert -shave 0x4 "${TMPDIR}/ss_top-triming.png" "${output_filename}" | |
| ## print output filename and exit | |
| [[ -p /dev/stdout ]] && echo "${output_filename}" | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment