forked from vitorgalvao/tiny-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabelcolor
More file actions
executable file
·52 lines (42 loc) · 1.1 KB
/
Copy pathlabelcolor
File metadata and controls
executable file
·52 lines (42 loc) · 1.1 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
readonly program="$(basename "${0}")"
function usage {
echo "
Usage:
${program} <color> <file...>
Available color Options:
none (removes label), orange, red, yellow, blue, purple, green, gray
" | sed -E 's/^ {4}//'
}
if [[ "${1}" =~ ^(-h|--help)$ ]]; then
usage
exit 0
fi
if [[ "${#}" -lt 2 ]]; then
usage
exit 1
fi
readonly color_name="${1}"
shift
# Check if color is valid and convert name to appropriate index
readonly color_array=('none' 'orange' 'red' 'yellow' 'blue' 'purple' 'green' 'gray')
for i in "${!color_array[@]}"; do
[[ "${color_array[$i]}" == "${color_name}" ]] && color_index="${i}" && break
done
if [[ -z "${color_index}" ]]; then
echo "Please pick a valid color."
usage
exit 1
fi
# Set the label
osascript - "${color_index}" "${@}" << EOF &>/dev/null
on run argv
set labelIndex to (item 1 of argv as number)
repeat with i from 2 to (count of argv)
tell application "Finder"
set theFile to POSIX file (item i of argv) as alias
set label index of theFile to labelIndex
end tell
end repeat
end run
EOF