Created
September 20, 2015 20:08
-
-
Save lidio601/18487f88b2ff29bf09e1 to your computer and use it in GitHub Desktop.
Apply a Mac Tag / Label color to a file via Bash + AppleScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# http://stackoverflow.com/questions/6212219/passing-parameters-to-a-bash-function | |
# http://superuser.com/questions/168927/mac-os-x-how-to-change-the-color-label-of-files-from-the-terminal | |
# Set Finder label color | |
label() { | |
#echo "Default colors:" | |
#echo " 0 No color" | |
#echo " 1 Orange" | |
#echo " 2 Red" | |
#echo " 3 Yellow" | |
#echo " 4 Blue" | |
#echo " 5 Purple" | |
#echo " 6 Green" | |
#echo " 7 Gray" | |
colorvalue="$1" | |
file="$2" | |
osascript - ${colorvalue} ${file} << EOF >/dev/null 2>&1 | |
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 | |
} | |
# example call | |
# label 6 "$filename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment