Skip to content

Instantly share code, notes, and snippets.

Created January 23, 2011 16:20
Show Gist options
  • Select an option

  • Save anonymous/792181 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/792181 to your computer and use it in GitHub Desktop.
AppleScript to print all sender names of the filtered messages to a text file
(*
Save Sender List.scpt
by Alexander Jahraus
This Apple Mail Rule Action script extracts the names of the senders of
the filtered messages and writes them to a text file. Optionally with a
number and / or the date of the message.
Save it somewhere, then choose it as action for a Mail Rule, apply the Rule.
*)
-- change properties to customize to your needs
property output_file : "/Users/Alex/Desktop/Gästeliste.txt"
property withdate : true -- also print the date of the message
property numbered : true -- number the output lines
using terms from application "Mail"
to perform mail action with messages msgs
tell application "Mail"
set output to ""
set counter to 0
repeat with m in msgs
set counter to counter + 1
set sname to extract name from sender of m
set sdate to date sent of m
if numbered then set output to output & counter & ".\t"
set output to output & sname
if withdate then
set output to output & "\t" & sdate & "\n"
else
set output to output & "\n"
end if
end repeat
my writeToFile(output, output_file)
end tell
end perform mail action with messages
end using terms from
on writeToFile(this_data, target_file)
try
set open_target_file to ¬
(open for access (POSIX file target_file) with write permission)
write this_data to the open_target_file as «class utf8»
close access open_target_file
return true
on error
display alert ("Cannot open file \"" & target_file & "\"")
try
close access open_target_file
end try
return false
end try
end writeToFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment