Q: AppleScript to Export Mails as PDF?

M

markus.hartbauer

Hi! I need to batch export my Entourage Mails to the filesystem. I've
created an AppleScript which does that but I'd rather export a PDF
Version of the Mail-Texts than the proprietary Entourage Files.

Can anyone please give me a hint how to use AppleScript to Save an
Entourage Message Item as PDF?

Thank you & Best regards,
M


FYI here is my Script - you may use it freely:

(*
max Exporter...
© 2008 max
*)

tell application "Microsoft Entourage"
activate
set theSelection to current messages
if theSelection is equal to {} then error "No message(s) selected!"

display dialog "Project:" default answer ""
set projekt to text returned of result
if projekt is equal to "" then error "No Project specified!"

set docFolder to (path to documents folder from user domain)
set fpath to (choose folder default location docFolder with prompt ¬
¬
"Select target folder" without multiple selections allowed) as
string

repeat with theMessage in theSelection

set messageDate to time received of theMessage
copy messageDate to b
set b's month to January
set messageYear to year of messageDate
set messageMonth to month of messageDate
set messageMonthNum to 1 + (messageDate - b) div 2500000
set messageDay to day of messageDate
set messageSubject to subject of theMessage
set messageSender to sender of theMessage
set messageSenderName to display name of messageSender

set newFname to "" as string
set fname to (subject of theMessage) as string
if ((count of characters of fname) > 40) then
set fname to ((characters 1 thru 37 of fname) & "...") as string
end if
set fname to projekt & " " & (messageYear as text) & (text -2 thru
-1 of ("00" & messageMonthNum)) & (text -2 thru -1 of ("00" &
messageDay)) & " " & (messageSenderName) & ": " & fname

if (fname contains ":") then
repeat with j in characters of fname
if (j as string = ":") then
set newFname to newFname & "-"
else
set newFname to newFname & j
end if
end repeat
set fname to newFname
end if

set fname to (fpath & fname) as string

tell application "Finder"
if (exists file (fname)) then
set k to 1
repeat while (exists file (fname & "-" & (k as string)))
set k to k + 1
end repeat
set fname to (fname & "-" & (k as string))
end if
end tell

save theMessage in fname

tell application "Finder"
update file fname
tell fpath
update every item with necessity
end tell
end tell

end repeat

end tell
 
E

Ed Kimball

Hi! I need to batch export my Entourage Mails to the filesystem. I've
created an AppleScript which does that but I'd rather export a PDF
Version of the Mail-Texts than the proprietary Entourage Files.

Can anyone please give me a hint how to use AppleScript to Save an
Entourage Message Item as PDF?

Thank you & Best regards,
M


FYI here is my Script - you may use it freely:

(*
max Exporter...
© 2008 max
*)

tell application "Microsoft Entourage"
activate
set theSelection to current messages
if theSelection is equal to {} then error "No message(s) selected!"

display dialog "Project:" default answer ""
set projekt to text returned of result
if projekt is equal to "" then error "No Project specified!"

set docFolder to (path to documents folder from user domain)
set fpath to (choose folder default location docFolder with prompt ¬
¬
"Select target folder" without multiple selections allowed) as
string

repeat with theMessage in theSelection

set messageDate to time received of theMessage
copy messageDate to b
set b's month to January
set messageYear to year of messageDate
set messageMonth to month of messageDate
set messageMonthNum to 1 + (messageDate - b) div 2500000
set messageDay to day of messageDate
set messageSubject to subject of theMessage
set messageSender to sender of theMessage
set messageSenderName to display name of messageSender

set newFname to "" as string
set fname to (subject of theMessage) as string
if ((count of characters of fname) > 40) then
set fname to ((characters 1 thru 37 of fname) & "...") as string
end if
set fname to projekt & " " & (messageYear as text) & (text -2 thru
-1 of ("00" & messageMonthNum)) & (text -2 thru -1 of ("00" &
messageDay)) & " " & (messageSenderName) & ": " & fname

if (fname contains ":") then
repeat with j in characters of fname
if (j as string = ":") then
set newFname to newFname & "-"
else
set newFname to newFname & j
end if
end repeat
set fname to newFname
end if

set fname to (fpath & fname) as string

tell application "Finder"
if (exists file (fname)) then
set k to 1
repeat while (exists file (fname & "-" & (k as string)))
set k to k + 1
end repeat
set fname to (fname & "-" & (k as string))
end if
end tell

save theMessage in fname

tell application "Finder"
update file fname
tell fpath
update every item with necessity
end tell
end tell

end repeat

end tell

I haven't tried to program Entourage in AppleScript, but is it possible to
"Print" each message and effectively select "Save to PDF" in the Print
dialog?
 
M

markus.hartbauer

I haven't tried to program Entourage in AppleScript, but is it possible to
"Print" each message and effectively select "Save to PDF" in the Print
dialog?

That is indeed possible, would however lead to me entering some 100
filenames when I select some 100 items to print or create one large
PDF containing all 100 selected items - neither of which is what I'm
looking for.

Thanks anyway for the input.
 
E

Ed Kimball

That is indeed possible, would however lead to me entering some 100
filenames when I select some 100 items to print or create one large
PDF containing all 100 selected items - neither of which is what I'm
looking for.

Thanks anyway for the input.

I don't understand. Doesn't your current create a new file automatically for
each message? How is that different from creating a new PDF for each
message?
 
E

Ed Kimball

That's not how AppleScript was deigned to work. You send commands to
applications - but user interface scripting is a last resort.
As I said, I haven't tried it. I was assuming that the Print command was
scriptable. If that's not the case, than my approach won't work.
 
M

markus.hartbauer

Hi Jollyroger,

thank you for this good input. I've tried convert but it seems to
output a text format of the eMail which is no good for HTML formatted
eMails (which I get all the time due to our Exchange-environment). So
I can't really use/read the output PDF files.

BR
M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top