Hi all,
I have a script here that was actually put together by this forum (thanks to Rob if he’s still around); what it does is activate from a rule in Mail, take the text of the activating email, generate a .txt file from it, open Transmit, connect to a server, delete the contents of a particular directory, and upload this file in its place. It’s to put the contents of a regular mailing I receive online, basically.
Trouble is that it stopped working when I updated to the current version of Transmit from whatever aging one I was using, and I frankly haven’t a clue how to fix it. Hopefully it’s something basic. Can anyone suggest?
Here it is:
-- Note: The local file defined in the next 2 lines can be deleted by the script after upload if desired.
property destinationPath : path to desktop as text -- Customize if needed
property fileName : "Message Test.txt" -- Customize if needed
on perform_mail_action(Info)
tell application "Mail"
set selectedMessages to |SelectedMessages| of Info
repeat with eachMessage in selectedMessages
set content_ to content of eachMessage as string
my write_to_file(content_, (destinationPath & fileName), false)
my upload_(destinationPath & fileName)
end repeat
end tell
end perform_mail_action
on upload_(local_file_path)
-- begin user defined variables --
set myUserName to "username" -- NEED YOUR INFO
set myPass to "password" -- NEED YOUR INFO
set ftpServer to "foo.org" -- your ftp server -- NEED YOUR INFO
set initialPathOnFTPserver to "/www/directory/" -- NEED YOUR INFO
-- end user defined variables --
set fileToUpload to POSIX path of (local_file_path)
set tids to text item delimiters
try
set text item delimiters to "/"
set fileName to last text item of fileToUpload
set text item delimiters to tids
on error
set text item delimiters to tids
end try
tell application "Transmit"
activate
set newWindow to make new document at end
tell newWindow
connect to ftpServer as user myUserName with password myPass ¬
with initial path initialPathOnFTPserver with connection type FTP
delete remote item ((ftpServer & initialPathOnFTPserver & fileName) as text)
upload item fileToUpload
-- disconnect
end tell
--quit
end tell
end upload_
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
Much thanks,
- Brandon