Jump to content

Create Hotkey to Paste Color Data

Recommended Posts

Recently started using some new applications and the triggers I'd set up in Quicksilver are no longer working with those applications (BusyCal 2.6.3, for example).  My understanding is that Quicksilver has become somewhat out-of-date, so I'm trying Afred so see if it will work better. 


I'm looking for a way to paste specific color data over text (in TextEdit, Yojimbo, or OmniGraffle, for example).  In Quicksilver, I used the shelf to store the color data, then set up triggers with a different hotkey for each specific color: red, green, blue, etc.  (Red was "Shift-Option-Command-R", for example, and blue was "Control-B".) The shelf was a key step, because I couldn't figure out any other way to isolate the color data and put it into the command field.   I'm a teacher, and being able to paste colors over highlighted text quickly helps me when editing and giving feedback on others' writing (essays and articles, for example) or when composing my own lesson plans.  (Red means "cut this text", blue means "rethink this part", green means "I went ahead and fixed this for you").  


My question is: how do you set up a hotkey that will change the color of highlighted text to a specific color?  

Share this post

Link to post

For TextEdit it's fairly easy:


1: Create a new blank workflow

2: Add three hotkey triggers, one for each color you want

3: Add three RunNSApplescript Actions, again, one for each color.


Now, in each of the RunNSApplescript Action boxes, you will want to paste this:

on alfred_script(q)
tell application "System Events" to tell text area 1 of scroll area 1 of window 1 of process "TextEdit" to if exists then
set {x, y} to value of attribute "AXSelectedTextRange"
if x ≤ y then tell application "TextEdit" to set color of document 1's characters x thru y to {65535, 0, 0}
end if
end alfred_script

NOTE:  That I also copied the included 'alfred_script', so if you just copy and paste the above into the window, make sure you overwrite the others already in there.

ALSO NOTE:  The color in brackets for the above is RED as the format is {RED, GREEN, BLUE} and the initial value is all red, and zero green and blue.

For the green NSAppleScript {0, 65535, 0},

For the blue NSAppleScript {0, 0, 65535}


Then, connect your hotkey boxes to the appropriate NSAppleScript Boxes.

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...