This is probably very easy, but all the solutions I found were directed to specific applications.
At my work, we use an online system within the browser and I find myself every day setting the color of my messages using the mouse, which is very annoying. I just need to enter something like:
[green] The file was approved. [/green] <– this is just for illustration purposes since this question field doesn't have colors. These tags have no effect on the system.
or
[red] The file was denied. [/red].
Since the system is online, I can't use direct commands to set the color the text like we would do using TextEdit or any other real editor. So I wonder if there is a way to set the color of the text via Applescript (Automator Service) and send it to the clipboard because I know the browser will paste the formatted text with the right color.
Any other workaround will be appreciated.
Best Answer
As I do not have access to the web app you are using, I really cannot test if this will work for you.
The example AppleScript code, shown further below, with limited testing works for me as coded under macOS High Sierra.
Overview: Gets the selected text in Google Chrome and places it on the clipboard in the chosen color as HTML data, and pastes it back over the selected text.1
It uses an Automator Service, set to Service receives selected
text
inGoogle Chrome
, with [] Output replaces selected text left unchecked, to which a keyboard shortcut was assigned in System Preferences > Keyboard > Shortcuts > Services as: ⌃⌘CThe Automator Service uses a Run AppleScript action with the default code replaced entirely with the example AppleScript code.
Usage: After selecting text in Google Chrome then pressing ⌃⌘C a
choose from list
dialog box is shown where you can select which color to make the selected text on the clipboard. You do not need to use the mouse, just keystrokes, e.g. G-Enter for green, O-Enter for orange and R-Enter for red, or Esc to cancel the action.At this point, if all works right, the selected text will have been replaced with the colored text from the clipboard.1 (You will have to give it a second to let the service complete.)
Yes, it's a few keystrokes, but once comfortable with it I believe it will become second nature and be faster then having to reach for the mouse, etc.
The usual caveats may apply for the use of this in: System Preferences > Security & Privacy > Privacy > Accessibility
1Also note that the text box containing the selected text must allow pasting back the same HTML class data type and structure that was placed on the clipboard as given in the comments to the OP as answers to the questions I asked, otherwise this will not work as coded.
Example AppleScript code:
Note: The example AppleScript code is just that and other than any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.