Skip to content

Instantly share code, notes, and snippets.

@zhongweili
Forked from lucifr/image_process.bash
Created November 9, 2018 05:45
Show Gist options
  • Save zhongweili/00c24ecf729705c9435424252b8e8cae to your computer and use it in GitHub Desktop.
Save zhongweili/00c24ecf729705c9435424252b8e8cae to your computer and use it in GitHub Desktop.
a bash script for Alfred Extension to process screenshot.
#!/bin/bash
#
# requirements:
# - ImageMagick: http://www.imagemagick.org/script/binary-releases.php#macosx
# - image_optim: https://github.com/toy/image_optim
# - a scp supported host with ssh key paired
# setting up the enviroment
export PATH=/usr/local/bin:/opt/local/bin:/opt/local/sbin:$PATH
# please change the following variable to your own:
# folder: local dir for the image, default ~/Desktop/
# server: your scp server, e.g. 123.456.789.0
# username: your username for the server, e.g. root
# dir: remote dir for the image, e.g. /public/www/uploads/
# url: url for the image, e.g. http://yourwebsite.com/uploads/
folder=/Users/$(whoami)/Desktop/
server=123.456.789.0
username=root
dir=/public/www/uploads/
url=http://yourwebsite.com/uploads/
filename=`echo "{query}" | tr 'A-Z' 'a-z' | tr -s ' ' | tr ' ' '_'`_`date +%s`.png
path=$folder$filename
screencapture -i $path
while [ ! -f $path ]
do
sleep 1
done
width=`/usr/bin/osascript << EOT
tell application "System Events"
activate
set theWidth to (display dialog "Enter the width" default answer "650")
end tell
set theWidth to the text returned of theWidth as integer
return theWidth
EOT`
while [ -z "$width" ]
do
sleep 1
done
convert $path -resize "`echo $width`x>" $path
image_optim --no-pngout $path
echo \![{query}]\($url$filename\) | pbcopy
scp $path $username@$server:$dir
echo $filename uploaded!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment