I’ve got a fair way towards automating replies to mail in Mail.app – but strangely I can’t seem to figure out how to make it do a simple thing – copy the selection.
When someone called “John Smith” writes to me, I want to be able to select the “John” part and run a script which replies “Dear John”.
So all I need to do is tell the app to “copy the selection”, or “do the menu item copy of menu edit” or whatever but it’s proving surprisingly hard.
You can use ui scripting. Something like this:
tell application “Mail” to activate
tell application “System Events”
tell process “Mail”
keystroke “c” with command down
tell application “Mail”
set clip_data to (the clipboard) as text
editted: I forgot that you probably need to change ‘with command down’ to ‘using command down’.
Hi, thanks a lot, but it’s not actually working, and presumably that’s because this is not a free-standing Applescript, but one in the specific Mail Scripts folder, which begins with this mysterious incantation:
using terms from application "Mail"
which seems to make things behave differently. I can’t seem to make functions work in it either. Any ideas?