it works perfectly in the open Automator window but when I assign a keyboard shortcut and try I see the following error:

The action “Run AppleScript” encountered an error.

Hi. Sorry. I've only just noticed your feedback.

My guess would be that the modifier key(s) you're using for the shortcut is/are still down when the script runs and may be changing what's available in the applications' menus or the behaviour of the key code commands at the end. If it's not this, I don't know what else to suggest.

I don't know if there are more direct ways of scripting Google Chrome or Mail for your purposes, but assuming what you have already works, you need to insert these two lines immediately above the System Events block which pastes the clipboard contents into Mail:

Applescript:

set theEmailAddress to (the clipboard)setthe clipboard to text (offset of"@"in theEmailAddress) thruendof theEmailAddress

Things that are copied to the clipboard through the proxy of GUI scripting can take a fraction of a second to arrive there. The script gets no feedback about this and goes straight on to the next command. So the above code is best placed immediately before the pasting code rather than immediately after the copying code. Hopefully this will leave enough time for the clipboard contents to change before the editing code reads them. The 'set the clipboard to' command is a direct one from the script, so the script will probably wait for it to complete before moving on.

MacScripter has its own [applescript] and [/applescript] BBCode tags which people are encouraged to use when posting AppleScript code here. Code enclosed between them in the posting window appears as above when posted, with a clickable link which opens the code in the clicker's default editor. There's a button for these tags just above the text field in each posting window.