0 Replies Latest reply: Jul 23, 2010 2:06 PM by AppleScript Automation
AppleScript Automation Level 1 Level 1 (0 points)
I have a desire to use applescript and CUPS to solve a data conversion problem. The input to this process will be

single EML files, sometimes numbering in the 10s of 1000s. These would reside in a directory named INPUT.

I would use Automator to accept files from this folder at the time the workflow was initiated. The workflow would

contain two steps. First would be to select the location of INPUT. Second would be to run a piece of applescript.

This applescript would use Mail to open each EML file and print to CUPS. Within the CUPS configuration, I can

specify the destination of all things printed to the CUPS printer. Mail is the only application that will open EML

files on Mac out of the box.

I found this script that uses Mail to open a message, then uses AppleScript to grab specific parts of the message,

like headers and content, then writes these to a temporary text file, then prints the text file to the default

printer (set in the interface to be CUPS).

This script may work the way it is. I would not know. The minute I drop a Custom AppleScript step into my workflow

and drop this script in the workflow does not accept input and asks me to debug line by line. I’m unable to do

this. I don’t know how to write applescript and I’m not a programmer.


on run {input, parameters}

tell application “Mail”
set selectedMessages to |SelectedMessages| of input
repeat with eachMessage in selectedMessages
set theEmail to (headers of eachMessage as text) & return & return ¬
& (content of eachMessage as text)
set theTextFile to open for access “:MailText” with write permission
set theTempFile to (“:MailText” as alias)
write theEmail to theTextFile
close access theTextFile
do shell script “lpr /MailText”
tell application “Finder”
delete theTempFile
end tell
end repeat
end tell

return input
end run