Aplpescript to Upload Files with Transmit to an FTP and Copy URL location to cliboard
July 8th, 2006
This script (after painless hours of frustration with Applescript), does the following:
- Uploads dropped file to an FTP server using Transmit (the best FTP client, period)
- Gets the name of the file
- Changes the name so that whitespaces are replaced by %20
- Appends the name of the file to the URL you specify
- Copies the full URL to the clipboard
Why on Earth would you use this? I use to send links to big files instead of sending them as attachments by Mail. Also you can use it this to paste URL locations when editing a blog or when posting to a forum. The original was downloaded from the Transmit Scripts.
(*
Upload dropped files
To use script: replace commented areas with your server information.
Then select File->Save As… and choose Application as the File Format.
Once saved as an Application, any file you drop onto the script’s icon
will be uploaded to the server specified in the script.
Wade Cosgrove
*)
property myRemotePath : “” – the path where you want the files uploaded
property myHttpURL : “” – the WWW URL for the directory in myRemotePath
set myURL to “”
on open some_items
– bring Transmit to the foreground
activate application “Transmit”
tell application “Transmit”
– create new window to upload files with
make new document at before front document
tell document 1 – send commands to the frontmost document window
tell session 1 – sends commands to the first session in the window
– CHANGE: connects to the favorite with the name specified
– You may also use the connect to command to connect to a non-favorite server
if (connect to favorite with name “Peralta”) then
– CHANGE: change remote path if desired
– set their stuff to “Upload Destination”
if not (set their stuff to “temp”) then
display dialog “It was not possible to change the upload directory”
end if
– upload all items dropped onto the droplet
try
repeat with the_item in some_items
– ignoring result from upload
upload item the_item
–get the name of the file
set myURL to the_item as text
–This was a function, but script does not work when invoking the function, damn AS
set currentIndex to 1
set indexFound to -1
set haystack to myURL
set needle to “:”
repeat with letters in characters in haystack
if letters as string = needle then
set indexFound to currentIndex
end if
set currentIndex to currentIndex + 1
end repeat
set filename to strings (indexFound + 1) thru (length of myURL) of myURL
–replace whitespaces with %20
set newFilename to “”
repeat with letters in characters in filename
if letters as string = ” ” then
set newFilename to newFilename & “%20″
else
set newFilename to newFilename & letters
end if
set currentIndex to currentIndex + 1
end repeat
–append the name to the path
set myURL to (myHttpURL & newFilename)
–copy path to CB
set the clipboard to (myURL as text)
end repeat
end try
else
display dialog (“An error occured, could not connect to favorite”)
end if
– once the upload has finished, disconnect
disconnect
end tell
end tell
end tell
end open
Leave a Reply