Created
March 17, 2013 16:32
-
-
Save n8henrie/5182308 to your computer and use it in GitHub Desktop.
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/bash | |
set -e | |
#Originally posted at http://n8henrie.com/2013/01/automator-shell-script-uploading-images-to-wordpress-server | |
## This script was made as a service in Automator, may need adjustments to function otherwise. | |
## Look for portions that need to be replaced with your info, as denoted by [*stuff*] | |
for f in "$@" | |
do | |
## fix up the filename by removing spaces and special characters, prepend date | |
filename=$(date +"%Y%m%d")_$(basename "$f" | tr -d ' ' | sed 's/[^A-Za-z0-9._-]/_/g') | |
## Copy the file to uploads folder in /year/month subdirectories. | |
scp -P [*your server's ssh port number*] -p "$f" [*your ssh user*]@[*your domain*].com:[*path to your uploads folder, starting with /*]/wp-content/uploads/$(date +%Y)/$(date +%m)/$filename | |
## Make a string with all the urls (necessary if used with multiple files), close the for loop | |
pasteMe+="http://[*your domain*].com/wp-content/uploads/$(date +%Y)/$(date +%m)/$filename"'\n'; | |
done | |
## Get rid of final newline and copy the string with the http path(s) to the clipboard | |
echo -e $pasteMe | perl -0777 -pe 's|\n+\z||ims' | pbcopy | |
## Shoot a growl notification that it worked. | |
msg="Looks like the file(s) uploaded successfully to"$'\n\n'$(pbpaste)$'\n\n'"and the URL(s) copied to the clipboard."; | |
/usr/local/bin/growlnotify "n8upload" -m "$msg"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment