Last Updated on August 27, 2019 by Bakari Chavanu
Hi, I'm trying to figure out a Keyboard Maestro macro that would 1. Copy the text selected (for example a paragraph from a feature article in Safari) and then 2. Also copy the web link to that article. you would then be able to share this via email or messages. In iOS, this is achievable through apps such as Clips and Drafts, but i can't make it happen on the Mac using Keyboard Maestro. Can you help? Thanks for all your work BTW!
Awe, this workflow is right up Keyboard Maestro's alley. I have dozens of similar macros that reflect steps I take to accomplish an action in an application. But a warning: once you start creating these type of macros, you'll become spoiled and want to have KM do everything for you, and when it can't you'll have a terribly bad day. So you've warned.
To address the above question, I created a macro based on the actions the questioner wanted to have happen. The macro that I created could be made available for download, but it's better that you understand how I put it together so that you can create it on your own, as well as create similar macros based the process that I went through to develop it.
If you're new to KM, much of the following might not make complete sense. That's okay. Keyboard Maestro is not a highly difficult program to learn, but the more you learn about how to use it, the easier it becomes to create your macros without any programming required.
Check out my upcoming webinar about using Keyboard Maestro. I will also be presenting an online class for new and intermediate users of Keyboard Maestro.
Okay, so as a Mac automator, in order to create macro, you have to know what KM actions are available and what they can and cannot do.
When I put together the macro for this workflow, I thought about what needed to be done. I needed to:
- Copy selected text in Safari
- Create a new email
- Enter the recipient's email address
- Paste the selected text
- Paste the title and URL of the article
Next, I thought about what menu items are available in both Safari and Mail that can be triggered as a part of this workflow. I realized that Safari has a Share menu item that I might be able to use and trigger.
Here's how the macro looks. In in the next section, I'm going to explain each of the actions and why I selected them. The names of the actions the screenshot will appear a little different from the original names of the action. That's because when data is added to the action, the name of the action might change to reflect the changes made to the action. All the actions are of course in the Actions library.
- First, I chose the Copy to Named Clipboard action (see this article for more information about named clipboards) so that the selected text could be clipped to a named clipboard instead of the System Clipboard. I selected my “Temporary” named clipboard that I previously created, but I could have also created a new Named Clipboard and labeled it, “Email address.” You can create as many Named Clipboards in KM as you like or need. Named Clipboards simply hold items until they are replaced with a different item, similar to how it is done with the System Clipboard.
- To save a click or two for entering the recipient's email address in Mail, I used the “Prompt for User Input” action, which allows for inserting a variable, which in this case is an “email address”. Variables are holding places for bits of data that can be retrieved in another action.
- I selected the “Set Clipboard to Text” action, and inserted the “Email address” variable token. This action sets the email address I typed to the System Clipboard so that it can be pasted in the new email. Notice that's what's on the System Clipboard is different from what's in the Name Clipboard referenced above.
- In most multi-action macros, you should add brief pauses between actions to give KM the opportunity to execute the next action. By default the actions are 1.5 seconds, but sometimes 0.5 seconds is all that is needed.
- I know that Safari has an Email This Page menu item, so I chose the “Select Show Menu Item” action to trigger that menu item. This action opens a new email within Safari, and then it pastes the title of the webpage in the subject line, and the URL in the body of the email. Another way of handling this would be to have KM switch to Mail and then create a new email, and from there do some posting of data.
It's too bad that Apple doesn't include the ability to paste selected text using the above menu feature above. It is for this reason that Mac automation tools often feel the void found in the OS X system and other applications.
- When the new email is created, I know that the cursor will automatically appear in the “To” field. So at this point I can use the “Paste” action to paste the System Clipboard which contains the email address I typed. That address gets inserted in the email.
- Now in order to saving a few more clicks, I have KM tab forward 5 times to place the cursor in the body of the email. (Note: the number of tabs will depend on the fields you have set up in your Mail.) To set this up, I first used the “Type a Keystroke” action to simulate the Tab keystroke. I then inserted that action into a “Repeat” action so that it repeats the specified number of times.
- And finally, I use the“ Paste from Named Clipboard” action to paste the copied text saved to my Temporary Named Clipboard in the body of the email. When executed, this text will be pasted above the pasted URL.
Macro In Action
The above may seem like a lot of steps for something that can be done manually. But when you watch the video below you will see how KM executes the manual steps in about five seconds.
For the purposes of the video I triggered the above macro using the “Macro Palette Trigger”. I could also trigger with a hotkey.
I placed the macro in a macro palette folder I previously created. I then set the palette to appear when Safari comes to the forefront. And also for the purposes of this video, I selected to have the palette appear under my mouse cursor when it opens. Ordinarily, the palette appears on the left side of the Safari window.
The macro executes fairly quickly, so if you are new to Keyboard Maestro, you may have to watch the video a few times to see the macro in action.
There are few other ways the macro could be set up. Feel free to share your solution with us in the commend section below.
You have an Ask Mac Automator question? Post and send the question here, and if it's useful for other readers, I will post it in this column.
Sorry that this post was not useful for you!
Let me improve this post!
Tell me how I can improve this post?