August 15th, 2004 | Published in Uncategorized
I’m periodically moving files into my public web space to share with others, which presents a few minor issues:
- Macs are very tolerant of spaces in file names and several utilities (such as the screen grabber) insert them by default in some file names.
- It’s a small pain to type the URL.
So I wrote a quick script for the Big Cat Script Menu plugin that takes a file selected by the mouse and copies it to my public_html directory using scp, replacing all the spaces in the name with underscore (“_”) characters and copying the URL of the newly copied file to the clipboard for pasting into whatever means I’m using to relate the URL to someone else.
- I haven’t made the variables all friendly to change, but I’ve annotated the script so you can figure out what to change easily enough
- I use ssh-agent to make the process of copying stuff with scp relatively transparent and password free. If you don’t have public keys and an agent of some sort set up, this script won’t do you a ton of good. I recommend Xander Schrijen’s SSH Agent, which makes ssh keys under a Mac pointy-clicky easy, and Sam’s ssh agent tutorial as a decent set of instructions for generating and copying a public key for use with ssh. SSH Agent replaces the second half of his tutorial, especially if you add it to your startup items under System Preferences/Accounts/Startup Items.
- It will copy multiple files if you’ve selected multiple files, but only the last one to be copied will be available in the clipboard.
— copy to public_html by Michael Hall <firstname.lastname@example.org>
— For use with the Big Cat Scripts Plugin (http://ranchero.com/bigcat/)
— copy to the Big Cat "files" folder in ~/Library/Application Support/Big Cat Scripts
— Also: pretty much depends on having ssh keys set up on the remote server, either without a password, or with some kind of ssh-agent in place.
tell application "Finder"
repeat with i from 1 to (count of items in filelist)
– scrub out the spaces from the file name and replace them with the _ character
set AppleScript‘s text item delimiters to " "
set myname to (the name of item i of filelist)
set ScrubbedName to every text item in myname
set AppleScript‘s text item delimiters to "_"
set myname to every item of ScrubbedName as string
– copy the file over to the sever, replace ‘ix:public_html/’ to your remote host
do shell script "scp ‘" & (POSIX path of item i of filelist) & "’ ix:public_html/" & myname
– create a variable with the URL of the file on the remote server, replace "http://www.puddingbowl.org/~mph/" to your remote URL
set myFile to "http://www.puddingbowl.org/~mph/" & myname
– copy the variable to the clipboard for pasting
set the clipboard to myFile