Jump to content


Photo

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

colors CSS color conversion convert picker NSColor UIColor Objective-C panel

  • Please log in to reply
73 replies to this topic

#1 Tyler Eich

Tyler Eich

    Community Hero

  • Member
  • PipPipPip
  • 665 posts
  • LocationIndiana, USA

Posted 10 March 2013 - 10:53 PM

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, 28 January 2014 - 09:05 PM.

  • Andrew, phyllisstein, Florian and 11 others like this

#2 carlesba

carlesba

    Member

  • Member
  • PipPip
  • 43 posts

Posted 10 March 2013 - 11:00 PM

Very useful!


  • Tyler Eich likes this

#3 David Ferguson

David Ferguson

    Alfred Guru

  • Staff
  • 2,071 posts
  • LocationHuntsville, AL

Posted 10 March 2013 - 11:53 PM

Well done sir. 'Color' me impressed. I intended to  convert this one and make it essentially EXACTLY like this. You read my mind. Good work :)


  • Tyler Eich likes this
Twitter: jdfwarrior | Blog: dferg.us

#4 Tyler Eich

Tyler Eich

    Community Hero

  • Member
  • PipPipPip
  • 665 posts
  • LocationIndiana, USA

Posted 10 March 2013 - 11:58 PM

Well done sir. 'Color' me impressed. I intended to  convert this one and make it essentially EXACTLY like this. You read my mind. Good work :)


Awesome! :)

Please let me know if you have suggestions

#5 ctwise

ctwise

    Advanced Member

  • Member
  • PipPipPip
  • 303 posts

Posted 11 March 2013 - 11:54 AM

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


#6 Clinton Strong

Clinton Strong

    Member

  • Member
  • PipPip
  • 115 posts

Posted 11 March 2013 - 02:05 PM

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.


  • Tyler Eich likes this

#7 ctwise

ctwise

    Advanced Member

  • Member
  • PipPipPip
  • 303 posts

Posted 11 March 2013 - 04:52 PM

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.



#8 David Ferguson

David Ferguson

    Alfred Guru

  • Staff
  • 2,071 posts
  • LocationHuntsville, AL

Posted 11 March 2013 - 05:25 PM

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... ?


  • Tyler Eich likes this
Twitter: jdfwarrior | Blog: dferg.us

#9 ctwise

ctwise

    Advanced Member

  • Member
  • PipPipPip
  • 303 posts

Posted 11 March 2013 - 06:02 PM

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.



#10 capsella

capsella

    Newbie

  • Member
  • Pip
  • 6 posts

Posted 11 March 2013 - 11:03 PM

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



#11 Tyler Eich

Tyler Eich

    Community Hero

  • Member
  • PipPipPip
  • 665 posts
  • LocationIndiana, USA

Posted 12 March 2013 - 02:45 AM

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 :)

#12 ctwise

ctwise

    Advanced Member

  • Member
  • PipPipPip
  • 303 posts

Posted 12 March 2013 - 11:06 AM

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.


  • Tyler Eich likes this

#13 David Ferguson

David Ferguson

    Alfred Guru

  • Staff
  • 2,071 posts
  • LocationHuntsville, AL

Posted 12 March 2013 - 11:36 AM

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

 

The man makes a great point :)


Twitter: jdfwarrior | Blog: dferg.us

#14 phyllisstein

phyllisstein

    Advanced Member

  • Member
  • PipPipPip
  • 371 posts
  • LocationNew York, NY

Posted 12 March 2013 - 01:39 PM

Thanks, that's great! And even handy for some of the LaTeX stuff I do.


  • Tyler Eich likes this

alp, Alfred.framework, and my assorted workflows are now abandonware. You can find them at https://github.com/p...stein/Workflows.

 


#15 capsella

capsella

    Newbie

  • Member
  • Pip
  • 6 posts

Posted 12 March 2013 - 04:39 PM

+1 for feeding back into Alfred


  • Tyler Eich likes this

#16 Tyler Eich

Tyler Eich

    Community Hero

  • Member
  • PipPipPip
  • 665 posts
  • LocationIndiana, USA

Posted 12 March 2013 - 11:21 PM

I've updated the workflow to include my first attempt at a color picker; thanks to everyone for their feedback!  :)

 

http://cl.ly/2y1d2w1f0y1w


  • capsella likes this

#17 capsella

capsella

    Newbie

  • Member
  • Pip
  • 6 posts

Posted 12 March 2013 - 11:28 PM

NICE!!! seems to be working perfectly :)


  • Tyler Eich likes this

#18 Tyler Eich

Tyler Eich

    Community Hero

  • Member
  • PipPipPip
  • 665 posts
  • LocationIndiana, USA

Posted 13 March 2013 - 10:48 AM

I've updated the workflow to include my first attempt at a color picker; thanks to everyone for their feedback!  :)

 

http://cl.ly/1A1U3n1d1H3S

 

I found a var_dump() line in my code that broke HSL conversions :(. The workflow has been updated to fix that; try this link: http://cl.ly/2y1d2w1f0y1w


  • DimerHunton likes this

#19 Clinton Strong

Clinton Strong

    Member

  • Member
  • PipPip
  • 115 posts

Posted 18 March 2013 - 05:20 PM

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.



#20 Tyler Eich

Tyler Eich

    Community Hero

  • Member
  • PipPipPip
  • 665 posts
  • LocationIndiana, USA

Posted 18 March 2013 - 06:15 PM

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 :)



Also tagged with one or more of these keywords: colors, CSS, color, conversion, convert, picker, NSColor, UIColor, Objective-C, panel

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users