select file, rename and upload based on URL input

Hi all,

I’ve got my mac setup as a staging server for a web site. I’d like to be able to send a URL to an applescript, have automator/applescript prompt me to select a single file, rename this file based on the filename in the URL and FTP upload it to the appropriate place on the server based on the URL path.

I started this in automator, but I’m stuck:

How can I break the URL into domain, path, filename? Or how can I put the path and the filename into a variable?

Once I do that, I can rename the file based on the filename variable, and upload it based on the path+new_filename.

Thanks for the help!

This should do the parsing for you OR at least get you started towards getting the output exactly as you want it.

set theURL to ""

if theURL begins with "http://" then set theURL to text 8 thru -1 of theURL

set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
set vars to text items of theURL
set {domain, filename} to {item 1, item -1} of vars
if (count vars) ≥ 3 then
	set folPath to items 2 thru -2 of vars as string
	set folPath to null
end if
set AppleScript's text item delimiters to tid

As for the rest of your request how exactly do you plan on calling the applescript and I have zero experience using automator.

james you are awesome! Thank you so much. This worked perfectly. I’ll post my script when I’m done, I think some folks might find it super handy. I know I will!

Glad I could be helpful!