Hey Neal,
<shrug> ![:sunglasses: :sunglasses:](https://forum.keyboardmaestro.com/images/emoji/apple/sunglasses.png?v=12)
Your process description has too many holes in it to say for certain.
Do you mean you are using both Microsoft Outlook.app and Mail.app?
Which versions on what OSX?
What's a “CMS”? A content management system, or something else?
Which one? What software?
The way I'd want this to work is something like this:
A) I'm reading an email from staff that, and I want to look them up in the CMS.
B) I press 1 key, and the process is done.
Given Mail and/or Outlook the front end of this is probably doable.
Without knowing the CMS software/system I cannot speculate on the back end.
Can the back end of this be done manually? Sure.
But without understanding the process a little better it's hard to advise.
In general – NEVER use a named clipboard – UNLESS it is of REAL benefit to do so.
People who use Keyboard Maestro often think they can copy and paste to/from a named-clipboard and leave the contents of the system clipboard untouched, but this is NOT true.
The system clipboard is the ONLY mechanism by which to copy/cut something as clipboard data.
(Some applications like TextWrangler are scriptable and can get and/or set the selection directly (usually as text) without using the clipboard at all).
Unless you deliberately restore the system clipboard it is changed every time you cut/copy/paste to/from a named-clipboard.
Therefore you should always use the system clipboard for clipboard operations – UNLESS you really do need to store it away.
If you DO need to store it away it is often better to use a variable than a named clipboard, but this depends upon several factors such as whether you're dealing with styled or plain text, how long you need to store the data, etcetera.
Here's an example of how to extract the Staff-ID of your example from Mail.app using AppleScript and the Satimage.osax using an Execute an AppleScript action:
------------------------------------------------------------
# REQUIRES Satimage.osax { http://tinyurl.com/dc3soh }
------------------------------------------------------------
tell application "Mail"
set selectedMessageList to selection
if selectedMessageList ≠ {} then
set selectedMessage to item 1 of selectedMessageList
tell selectedMessage
set messageText to its content
end tell
end if
end tell
try
# •• NOTE •• Discourse mangles the code in the next line.
# •• REMOVE •• the bullet in front of the 1 in the next line.
set staffID to find text "(\\d{9})@our.company.domain.com" in messageText using "\\•1" with regexp and string result
set the clipboard to staffID
tell application "myCMSapp" to activate
on error eMsg
beep
error "Find Staff ID Failed!" & return & return & eMsg
end try
------------------------------------------------------------
Due to poor rendering of some elements in the script I'm posting a downloadable text file:
Extract Staff-ID AppleScript.applescript.zip (1.1 KB)
Added 2016/01/29
After fighting with JXA (JavaScript for Applications) for 45 minutes I've pared that down to this (which doesn't require a 3rd party scripting addition):
(function () {
// Declare variables.
var mailAppRef, msgContentStr, reMatchedStr;
// Assign the Mail application object to a variable for later use.
mailAppRef = Application("Mail");
// Include functions from the StandardAdditions.osax.
// Without this you cannot set the Clipboard.
mailAppRef.includeStandardAdditions = true;
// Get the textual contents of the first selected message in Mail.app.
msgContentStr = mailAppRef.selection()[0].content();
// Use a regular expression to find the desired text in the messsge contents.
reMatchedStr = msgContentStr.match(/(\d{9})@our\.company\.email\.address\.com/);
// Set the Clipboard
mailAppRef.setTheClipboardTo(reMatchedStr[1]);
})();
To be run from an Execute a JavaScript For Automation action.
* I don't have any error-handling in the JavaScript, because I don't know how to do that yet.
You can use AppleScript to grab the message text and then use Keyboard Maestro's regular expressions actions to extract your ID-number.
You can select some text in your mail application and then use Keyboard Maestro to extract your ID-number.
And that brings us back to my way of looking at this task – if I did it regularly I'd want it to be as effortless as possible.
More than you wanted to know? ![:smiley: :smiley:](https://forum.keyboardmaestro.com/images/emoji/apple/smiley.png?v=12)
-Chris