Hey,

I've saved the following script as ~/bin/attach . It lets me create a new Mail message from the command line with a given file as an attachment. For example:

% attach foo/bar/baz.doc

Here's the script:

------------------------------------------------
#!/usr/bin/perl

use Mac::AppleScript qw(RunAppleScript);
use File::Spec;

my $file = shift or die "No file specified";
$file = File::Spec->rel2abs($file);

RunAppleScript(<<END);
tell application "Mail"
set newMessage to make new outgoing message
tell newMessage
set visible to true
tell content
make new attachment with properties {file name:"$file"} at after the last character
end tell
end tell
activate
end tell
END
------------------------------------------------


I created this by modifying Apple's "/Library/Scripts/Mail Scripts/Create New Message.scpt" . Hope it's useful to someone else.

Chris, would it be fun/possible to convert all that applescript to perl?

-Ken



Reply via email to