Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement