I’m wondering if there’s a way to achieve the following:
In macOS Mail when I click into a received email, I’d like to be able to quickly grab the senders email address with a shortcut and get it to the clipboard.
I don’t really seem to find a reliable way to do this with a macro.
The good thing is that the complete email with the name info is always in the same format. The bit you need is always after a < and before a > so, it is just a matter of extracting that bit of text.
I see that @ccstone has already provided a Regex solution to this exact thing here
And if you want to do this without Regex it can be done like this, by splitting the KM Variable into parts:
Oh the joy of getting automations to work! Thank you! I need to see if I can find an online course or something to get into understand how this works better. Let me know if you can recommend any resources.
I would say just keep trying things out (that are real tasks) read the Wiki for things like this and ask questions here.
Best way is to make Macros for things you actually need to do. That’s the quickest way to learn.
And rather than searching the Forum for previous similar questions - I find a general Google Search is better “Keyboard Maestro Your Question” - that will usually find the topic on this Forum quicker than searching in the Forum.
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/11/08 21:06
# dMod: 2022/11/08 21:06
# Appl: Mail
# Task: Extract Email Address from the Sender String of the Selected Message.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @Extract, @Email, @Address, @Sender, @String
--------------------------------------------------------
tell application "Mail"
set selectedMessageList to selection
if selectedMessageList ≠ {} then
set selectedMessage to item 1 of selectedMessageList
tell selectedMessage
set senderAddress to extract address from (get its sender)
end tell
end if
end tell
--------------------------------------------------------
The AppleScript variable senderAddress is assigned the value of email's sender's address. That value is not saved by the script which is only an example of how to acquire the value.
There are two main ways to make the value available to Keyboard Maestro.
1) You can assign a Keyboard Maestro variable within the AppleScript itself:
--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/11/08 21:06
# dMod: 2022/11/16 04:28
# Appl: Mail
# Task: Extract Email Address from the Sender String of the Selected Message.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @Extract, @Email, @Address, @Sender, @String
--------------------------------------------------------
tell application "Mail"
set selectedMessageList to selection
if selectedMessageList ≠ {} then
set selectedMessage to item 1 of selectedMessageList
tell selectedMessage
set senderAddress to extract address from (get its sender)
end tell
end if
end tell
--------------------------------------------------------
# NOTE – ALL Keyboard Maestro Variables are STRINGS.
set kmInstance to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
# Example of setting an AppleScript variable from a KM variable (commented-out)
# set asVarName to getvariable "local_copiedText" instance kmInstance
# Set a KM variable from an AppleScript variable or value.
setvariable "local_KmVarName" instance kmInstance to dataStr
end tell
# NOTE - The KM variable is a quoted string.
--------------------------------------------------------
2) You can capture the output of an AppleScript using the Execute an AppleScript action settings.