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.