This script is supposed to create a text file with each message that a mail rule applies to. It doesn’t create a new file and it doesn’t launch the application in the end of the script, but it gives no errors. I am very new at applescript. Any help?
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
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
set theSubject to subject of eachMessage
set theSender to sender of eachMessage
set theContent to content of eachMessage
set this_story to theSubject & "RRRRRRRRRR" & theSender & "RRRRRRRRRR" & theContent
set this_file to ("Macitosh HD:Users:mjdth:Documents:Oranged:Software:Studio Manager Folder:Serials:NewNumber")
(*set this_file to (((path to desktop folder) as text) & "NewNumber")
*)
my write_to_file(this_story, this_file, false)
end repeat
end tell
end perform mail action with messages
end using terms from
tell application "AutoSN"
activate
end tell
thanks for the tip. Only problem is now both mail and the other application freeze once the other application tries to run a different applescript to create a new mail message.
the other application is a realbasic application that, when opened, opens the text file saved by the applescript, creates a serial number, saves the serial number to a file, and then sends the serial number through mail with another applescript.
The serial number gets generated fine and saved fine, but i think there is a problem when the program tries to execute another applescript. anything I can do to fix this?
ooh and i also put a beep after the application launch thing, but it never happens.
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
set theSubject to subject of eachMessage
set theSender to sender of eachMessage
set theContent to content of eachMessage
set this_story to theSubject & "ABCD1234" & theSender & "ABCD1234" & theContent
set this_file to ("Crap:NewNumber")
(*set this_file to (((path to desktop folder) as text) & "NewNumber")
*)
my write_to_file(this_story, this_file, false)
end repeat
end tell
tell application "AutoSN"
activate
end tell
beep
end perform mail action with messages
end using terms from
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
Have you any problem reading the contents of e-mails coming from outlook express?
I run scripts from rules, with the contents as argument… he works great with emails from Mail, but something on the outlook encoding get me in trouble.