To use this (or any) script in a program like Apple Mail, you could create a service in Automator.
Launch the Automator program.
When it says Choose a type for your document, select Service and click Choose
In the top dialog, select Service receives no input in Mail.app (or, the name of your program, or any application if that's what you want).
You will insert one action: From the Utilities group, double-click Run AppleScript.
Select the text that says
(* Your script goes here *)
and paste in the script you want to run. In your case, the script you want to paste is
tell application "Mail"
set theSelection to selection
set theMessage to item 1 of theSelection
set theSubject to subject of theMessage
tell application "Address Book"
set theGroup to make new group with properties {name:theSubject}
end tell
set theRecipients to to recipients of item 1 of theMessage
repeat with a from 1 to count theRecipients
set theRecipient to item a of theRecipients
tell application "Address Book"
set theName to name of theRecipient
tell application "Mail" to set theAddress to address of theRecipient
set thePerson to make new person with properties {first name:name of theRecipient}
make new email at end of emails of thePerson with properties {value:theAddress}
add thePerson to theGroup
end tell
end repeat
set theRecipients to cc recipients of item 1 of theMessage
repeat with a from 1 to count theRecipients
set theRecipient to item a of theRecipients
tell application "Address Book"
set theName to name of theRecipient
tell application "Mail" to set theAddress to address of theRecipient
set thePerson to make new person with properties {first name:name of theRecipient}
make new email at end of emails of thePerson with properties {value:theAddress}
add thePerson to theGroup
end tell
end repeat
tell application "Address Book" to save
end tell
Once you have done that, go to the File menu and click Save.
Give the service a name you will remember, like "Add Recipients to Group".
Then when you are in Mail, you can select a message or messages and go to the Mail menu in the menu bar, then the Services menu in the Mail menu, and select the service Add Recipients to Group.
I've tried with Automator without succeeding looping through dropped files.
Here's a folder action script that does what you want, and how to attach it to a folder :
1. Open AppleScript Editor
2. Paste the following script into a new document
property mail_subject : "An image for you"
property mail_plain_content : "Attached you will the image you required." & return & return & "Best Regards" & return & "Automator"
property mail_html_content : "Attached you will the image you required.<br><br>Best Regards<br>Automator"
on adding folder items to this_folder after receiving these_items
processItems(these_items)
end adding folder items to
on processItems(these_items)
repeat with i from 1 to (count of these_items)
set this_item to item i of these_items
if isFolder(this_item) then
processItems(getFolderItems(this_item))
else
processFile(this_item)
end if
end repeat
end processItems
on processFile(this_file)
set mail_address to RemoveExtension(getFileName(this_file))
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:mail_subject, plain text content:mail_plain_content, content:mail_html_content}
tell newMessage
make new recipient with properties {email address:{address:mail_address}}
make new attachment with properties {file:this_file as alias}
send
end tell
activate
end tell
end processFile
on isFolder(this_item)
tell application "System Events" to return (exists folder (this_item as string))
end isFolder
on RemoveExtension(this_name)
-- This function comes from :
-- http://www.macosxautomation.com/applescript/sbrt/index.html
if this_name contains "." then
set this_name to (the reverse of every character of this_name) as string
set dot_offset to the offset of "." in this_name
set this_name to (text (dot_offset + 1) thru -1 of this_name)
set this_name to (the reverse of every character of this_name) as string
end if
return this_name
end RemoveExtension
on getExtension(this_name)
if this_name contains "." then
set this_name to (the reverse of every character of this_name) as string
set dot_offset to the offset of "." in this_name
set this_name to (text 1 thru (dot_offset - 1) of this_name)
set this_name to (the reverse of every character of this_name) as string
return this_name
else
return ""
end if
end getExtension
on getFileName(this_file)
tell application "Finder" to return name of this_file
end getFileName
on getFolderItems(this_folder)
tell application "Finder" to return items of this_folder
end getFolderItems
3. Save it in your ~/Library/Scripts/Folder Action Scripts Folder
Menu File > Save
Go to the right folder : press cmd+G and paste:
~/Library/Scripts/Folder Action Scripts
and click Go
Save as : Image - Email using name as address.scpt (for example)
Format : Script
4. Create a new folder that will be watched for added items
5. Associate the script to the folder
In the Finder, right click on your folder, then select Services > Folder Actions Setup
Select the new created Image - Email using name as address.scpt script
You're done, drop a file whose name is an address, mail will be sent.
Best Answer
As far as I can tell, there is no direct way. You would have to use applescript to select the text and set the formatting in the Mail application after the fact... (Example below taken from the web...)