10

EDIT: I use X11 now and I have no problem.

I've seen many apps posted here, but right now in my laptop with 19.10 none of them work.

I've tried Agave, Gpick, and Grabc .

They all give back the color black regardless of where I put the cursor on #000000

6
  • is there a workaround? Commented Oct 24, 2019 at 22:14
  • 1
    Are you really using 9.10, or did you mean to type 19.10? Please click edit and fix it if that's what you meant. Commented Oct 24, 2019 at 22:17
  • 2
    That's expected behavior if you are using Wayland. In Wayland, applications do not have permission to see pixels outside their own box. (Yes, it's a reported bug). The workaround is to logout and login to an X session. Use the little 'gear' icon on your password screen to select Ubuntu using X. Commented Oct 24, 2019 at 22:32
  • Ubuntu 9.10 from 2009-October? or Ubuntu 19.10 from 2019-October. There is a decade of difference between them... Commented Oct 24, 2019 at 23:02
  • Sorry all! Yeah I meant 19.10 Commented Oct 25, 2019 at 18:42

4 Answers 4

5

IMHO it is not very efficient to open Firefox to pick colors, at least I wouldn't do that, especially because you can implement Ubuntu native tricks like @Porcupine answer, which I'd like to expand, in two separate ways.

CLI command

Indeed you could open BASH and type a command to get the color selection tool with zenity (works in Wayland and X11 and, on Ubuntu 22.04, requires no additional libraries):

zenity --color-selection

you can even automatically copy the output (which is an RGB color) with the following command, that can be conveniently set as an alias:

zenity --color-selection | xsel --clipboard

But if you, like me, find this a bit painful, read on.

Keyboard shortcut + HEX output

If you want to take stuff to the next level, you can set the above command to be called via keyboard shortcut. To do that:

  • re-write the above command as a function
  • bonus: append some functionality to convert the RGB output to HEX (which is what I need for instance in React Native and could be useful to others as well)
    • e.g. convert rgb(255,255,255) to #ffffff
  • encapsulate it into a my_function_script.sh file
#!/bin/bash

function pick-hex() {
  # Pick a color and return it into the clipboard as HEX, not RGB

  # Use Zenity to select an RGB color
  color=$(zenity --color-selection)

  # Remove the "rgb(" prefix and ")" suffix
  color=${color#rgb(}
  color=${color%)}

  # Split the color into individual RGB values
  IFS=',' read -r red green blue <<< "$color"

  # Trim leading spaces
  red=$(echo "$red" | xargs)
  green=$(echo "$green" | xargs)
  blue=$(echo "$blue" | xargs)

  # Convert RGB to hexadecimal
  red_hex=$(printf "%02X" "$red")
  green_hex=$(printf "%02X" "$green")
  blue_hex=$(printf "%02X" "$blue")

  # Combine the RGB values to form the hexadecimal color
  hex_color="#$red_hex$green_hex$blue_hex"

  # Copy the color to the clipboard for use in other applications
  echo -n "$hex_color" | xsel --clipboard
}

pick-hex

Once the above is in place, setup a keyboard shortcut for this script in Ubuntu:

  • go to"Keyboard Shortcuts"
  • add a new custom shortcut and click the "+" or "Add" button.
  • in the command field, enter the path to your script (e.g. /path/to/my_function_script.sh).
  • assign a custom key combination to the shortcut e.g. I like shiftaltc

and you end up with a legit color picking tool called via keyboard from anywhere in Ubuntu.

4

Here is a workaround.

Open your image, a screenshot you made or a web page with Firefox.

file:///your_directory/your_image.png

In Firefox go to : Tools > Web Developer > Eyedropper

Left click on the color you want. It's copied in the clipboard.

For example : Hex: #497FC1

3

Works in Wayland and X11

zenity --color-selection

6
  • While I can understand the confusion, this isn't what the OP wants. He wants to point at a color he sees on the screen and find out what color it is. Commented Nov 17, 2022 at 21:08
  • 1
    @MDeBusk And what does my answer does? Commented Nov 18, 2022 at 6:38
  • 1
    It's not so much what it does, but what it doesn't do. A color selection dialog lets you choose a color from the particular window displayed in the dialog box rather than anywhere on the screen. Commented Nov 18, 2022 at 13:51
  • 2
    @alfx Hi! Your suggested edit was rejected because it actually is a proper answer that deserves being posted separately! So can you please post it as such? Thanks! And do ping me here (as @beastofcaerbannog) If you do post it, so that I can upvote it! Commented Oct 31, 2023 at 12:52
  • hi @BeastOfCaerbannog, I did as you recommended, thanks for the advice Commented Oct 31, 2023 at 16:12
0

Here is the X11 native solution that

  • doesn't require any external packages like Agave, Gpick, or Grabc etc.
  • and it doesn't limit to web pages (like the previous answer) either

Just run xmag. From its man page:

  • The xmag program allows you to magnify portions of an X screen.
  • The area can be dragged out to the desired size by pressing Button 2.
  • Once a region has been selected, a window is popped up showing a blown up version of the region in which each pixel in the source image is represented by a small square of the same color.
  • "Pressing Button1 in the enlargement window shows the position and RGB value of the pixel under the pointer until the button is released" -- this, is the X11 native solution for Color Picker.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.