Jump to content

Colors—convert color formats & access the OS X color panel


Recommended Posts

Colors v2.0.0

 

Get it from Packal (Recommended)

 

Quick Summary:

This workflow can process and convert all CSS color formats and several Objective-C formats, namely NSColor (calibrated and device) and UIColor. It also provides an interface to the OS X color panel for easier color manipulations.

 

It's written in native code (i.e. it's really fast).

 

Quick Preview:

colors-hexadecimal.png

You can find a full description on Packal.

 

Direct downloadsource code on Github

Edited by Tyler Eich
Link to comment

This is excellent, it's almost a complete replacement for Robert Horvath's Hex Color/Picker workflow. That version does one additional thing yours doesn't, it brings up the color picker when '#' is entered without a hex code. Here's the code it uses to either throw up the color picker or just pass on the hex code:

 

 

if "{query}" == "pick"
    `OUTPUT=$(osascript -e 'tell application "Finder"' -e 'activate' -e 'choose color' -e 'end tell' | ruby -e 'puts "#" + STDIN.read.split(",").map{|y| "%.2x" % [y.to_i>>8]}.join'); printf $OUTPUT | pbcopy`
else
    print "{query}"
end
Link to comment

This is amazing. You win the internets.

 

Oh, and adding to the color picker code ctwise posted, you could just add a bit of AppleScript to show the color in Alfred:

 

OUTPUT=$(osascript -e 'tell application "Finder"' -e 'activate' -e 'choose color' -e 'end tell' | ruby -e 'puts "#" + STDIN.read.split(",").map{|y| "%.2x" % [y.to_i>>8]}.join'); printf $OUTPUT | pbcopy; osascript -e 'tell application "Alfred 2"' -e "search \"$OUTPUT\"" -e 'end tell'

You can paste that code in to Terminal if you want to see it in action.

Link to comment

This is amazing. You win the internets.

 

Oh, and adding to the color picker code ctwise posted, you could just add a bit of AppleScript to show the color in Alfred:

 

OUTPUT=$(osascript -e 'tell application "Finder"' -e 'activate' -e 'choose color' -e 'end tell' | ruby -e 'puts "#" + STDIN.read.split(",").map{|y| "%.2x" % [y.to_i>>8]}.join'); printf $OUTPUT | pbcopy; osascript -e 'tell application "Alfred 2"' -e "search \"$OUTPUT\"" -e 'end tell'

You can paste that code in to Terminal if you want to see it in action.

 

Yes, that's much better. A little experimentation shows that creating two script filters for '#' - one that requires arguments and one that doesn't allow them works very well. The one without arguments just displays a single entry to launch the color picker and trigger the above script. The other is untouched from the current workflow.

Link to comment

Yes, that's much better. A little experimentation shows that creating two script filters for '#' - one that requires arguments and one that doesn't allow them works very well. The one without arguments just displays a single entry to launch the color picker and trigger the above script. The other is untouched from the current workflow.

 

Creating it as two script filters though makes it show as two items if the user hasn't typed a space yet though correct? If they have only typed '#' then it shows two seemingly identical pieces? Granted, the other would disappear as soon as you pressed space but still.. He could easily just add an if statement to check and see IF a value was passed to the function and if not, display the color picker, otherwise, convert the color passed. Unless I'm misunderstanding something... ?

Link to comment

Creating it as two script filters though makes it show as two items if the user hasn't typed a space yet though correct? If they have only typed '#' then it shows two seemingly identical pieces? Granted, the other would disappear as soon as you pressed space but still.. He could easily just add an if statement to check and see IF a value was passed to the function and if not, display the color picker, otherwise, convert the color passed. Unless I'm misunderstanding something... ?

 

Nope, you're correct. It's just a little simpler.

Link to comment

This is excellent, it's almost a complete replacement for Robert Horvath's Hex Color/Picker workflow. That version does one additional thing yours doesn't, it brings up the color picker when '#' is entered without a hex code. Here's the code it uses to either throw up the color picker or just pass on the hex code:

if "{query}" == "pick"

`OUTPUT=$(osascript -e 'tell application "Finder"' -e 'activate' -e 'choose color' -e 'end tell' | ruby -e 'puts "#" + STDIN.read.split(",").map{|y| "%.2x" % [y.to_i>>8]}.join'); printf $OUTPUT | pbcopy`

else

print "{query}"

end

This is amazing. You win the internets.

Oh, and adding to the color picker code ctwise posted, you could just add a bit of AppleScript to show the color in Alfred:

OUTPUT=$(osascript -e 'tell application "Finder"' -e 'activate' -e 'choose color' -e 'end tell' | ruby -e 'puts "#" + STDIN.read.split(",").map{|y| "%.2x" % [y.to_i>>8]}.join'); printf $OUTPUT | pbcopy; osascript -e 'tell application "Alfred 2"' -e "search \"$OUTPUT\"" -e 'end tell'
You can paste that code in to Terminal if you want to see it in action.

Creating it as two script filters though makes it show as two items if the user hasn't typed a space yet though correct? If they have only typed '#' then it shows two seemingly identical pieces? Granted, the other would disappear as soon as you pressed space but still.. He could easily just add an if statement to check and see IF a value was passed to the function and if not, display the color picker, otherwise, convert the color passed. Unless I'm misunderstanding something... ?

can you post an example of combining the 2 options for the hex script filter?

Thanks to everyone for their feedback! I like the color picker idea; I'm searching for the best way to implement it and using several of the suggestions that have been posted here.

A conditional statement within my code feels like the cleanest solution; I was thinking of latching a 'show color picker' item for all script filters before any input is given (so 'rgb', 'hsl', '#', and 'c' without any code input would allow you to use the color picker). I am still deciding how the color should be used; should it be copied to the clipboard, fed back into Alfred, etc.? I'm leaning toward feeding the color back into Alfred, just so you have more control over what is copied.

Comments are welcome :)

Link to comment

Thanks to everyone for their feedback! I like the color picker idea; I'm searching for the best way to implement it and using several of the suggestions that have been posted here.

A conditional statement within my code feels like the cleanest solution; I was thinking of latching a 'show color picker' item for all script filters before any input is given (so 'rgb', 'hsl', '#', and 'c' without any code input would allow you to use the color picker). I am still deciding how the color should be used; should it be copied to the clipboard, fed back into Alfred, etc.? I'm leaning toward feeding the color back into Alfred, just so you have more control over what is copied.

Comments are welcome :)

 

Feed back into Alfred. It lets you pick a color and then the representation.

Link to comment

Just a quick suggestion for the color picker: You can show the color picker with any application, not just Finder. You could even use Alfred 2 in the `tell` command. The main benefit is that it won't show any unrelated windows with the color picker, and you can easily bring it back up by invoking Alfred.

 

This pretty much replaced the color picker application I used to use. Clicking the magnifying glass icon in the color picker replaces apps like ColorSnapper. Pretty cool.

Link to comment

Just a quick suggestion for the color picker: You can show the color picker with any application, not just Finder. You could even use Alfred 2 in the `tell` command. The main benefit is that it won't show any unrelated windows with the color picker, and you can easily bring it back up by invoking Alfred.

 

This pretty much replaced the color picker application I used to use. Clicking the magnifying glass icon in the color picker replaces apps like ColorSnapper. Pretty cool.

I remember trying this, but I couldn't get it to work; I'll give it another go, because I would love to not change app focus just to show a color picker.

Does anybody know a way to include an opacity slider in the color picker dialog? I'd love to allow opacity selection from there, but I've not found a way to do it.

Thanks :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...