Skip to content

Instantly share code, notes, and snippets.

@n8henrie
Created March 17, 2013 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8henrie/5182308 to your computer and use it in GitHub Desktop.
Save n8henrie/5182308 to your computer and use it in GitHub Desktop.
#!/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