-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcolorpicker
More file actions
executable file
·27 lines (19 loc) · 859 Bytes
/
colorpicker
File metadata and controls
executable file
·27 lines (19 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
# Adapted from https://unix.stackexchange.com/a/724963/5097
clipboard="${clipboard-1}"
set -euo pipefail
# Call gdbus to run color picker widget
output="$(gdbus call --session --dest org.gnome.Shell.Screenshot --object-path /org/gnome/Shell/Screenshot --method org.gnome.Shell.Screenshot.PickColor)"
# assign floating point values (0.0-1.0) to array of length 3
readarray -t colors < <(grep -o "[0-9\.]*" <<< "$output")
# Convert to 255-based RGB format
for ((i = 0; i < ${#colors[@]}; i++)); do
colors[$i]="$(printf '%.0f' "$(echo "${colors[$i]} * 255" | bc)")"
done
echo "RGB: ${colors[0]} ${colors[1]} ${colors[2]}"
as_hex="$(printf "#%02x%02x%02x" "${colors[0]}" "${colors[1]}" "${colors[2]}")"
echo "HEX: $as_hex"
if [ -n "$clipboard" ]; then
echo -n "$as_hex" | xclip -selection clipboard
echo "(copied to clipboard)"
fi