AppleScript for Instant File Uploads and URLs

Let me preface this with the fact that I am not a programmer (knowing laughs from anyone who is) and I managed to write this using AppleScript. It is a little scary looking but really isn’t that bad. If you’ve got a Mac, give it a shot!

The Issue
It is always a hassle for me to stop in the middle of writing a post to log on to a server and upload files that I need to link to. I also have server space in several locations so remembering that ~ in one or that I’m woodward_t in the other was a hassle.

So . . .
Here’s a little AppleScript I wrote to help myself out. It’s a droplet (you drag files onto it to make it work) that I leave on my desktop. It uploads the file to the server (I have three, one for each server) and puts the URL to that file on my clipboard so I can then paste directly into the post.

Stuff to keep in mind-

I tried to comment (denoted by –) it up so you could see clearly what was going on. All things you’ll have to change are in all caps.
It’ll handle multiple files but it’d only give you the URL of the last one that uploads.

If your account name is different from the folder used in your URL you’ll have to play with things a bit. In this case I log in with a user name that is the same as my URL folder but it’s not too difficult to change it so it works the other way too. I’d be happy to help if you’re interested enough to ask.

Cut and paste the text below into your script editor and save it as an application.


on open files_

--sets the name you use to log into the server

set user_name to "USERNAME"

--sets the server name set server_name to "afp://SERVERNAME"

--checks to see if you're already logged in

tell application "Finder"

if not (exists the disk user_name) then

mount volume server_name & "/" & user_name as user name user_name

end if

end tell

--loops through the files dropped on the icon

repeat with file_ in files_

tell application "Finder"

duplicate file_ to user_name & ":Sites"

set fileName to name of file_

end tell

--put the main portion of your URL in below as this is what your clipboard will be set to

set url_name to "http://URLADDRESS" & user_name & fileName

tell application "Finder"

set the clipboard to url_name

end tell

end repeat

end open