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.
You can use AppleScript to execute shell scripts, so you can use:
do shell script ("lpoptions -d printername")
Replace printername
with the actual printer name. It may not be exactly as it shows in System Preferences (I think ALL non-alphanumeric characters are replaced with underscores, but I'm not certain) so you can view your list of printers with:
lpstat -p
Best Answer
I believe I've roughly translated your steps into a working AppleScript:
Note that the part at the beginning (with the delay and window selection) is necessary to ensure that an active window is open in the printer app; otherwise, the Settings panel won't be able to open if a window isn't already open.
Although the following isn't what the OP is asking for, in case anybody else is looking to do this with a printer that doesn't supply a "Print Test Page" option in the Settings panel, here's an alternate solution:
To accomplish this, replace lines 5–7 of the above with
click menu item "Print Test Page" of menu "Printer" of menu bar 1
.