[zsh] Set folder color and overlay a character (macOS 26)

Here’s a sample script using a new feature introduced in macOS 26:
it allows you to set a folder color and place a single character inside the folder icon.

I don’t think anyone has shared this yet, so I’m posting it here.

#!/bin/zsh
#com.cocolog-nifty.quicktimer.icefloe
#set -x
#export PATH=/usr/bin:/bin:/usr/sbin:/sbin

#########################
#For Emoji
#フォルダを作ります
# Create a folder
/bin/mkdir -p ~/Desktop/ColorFolder

STR_TMP_DIR_PATH=$(/usr/bin/mktemp -d)
STR_TMP_JSON_PATH="${STR_TMP_DIR_PATH}/tag.json"
STR_TMP_PLIST_PATH="${STR_TMP_DIR_PATH}/label.plist"

#JSONを作ります
# Create a JSON file with the emoji you want to render
/bin/echo "{\"emoji\":\"🔍\"}" > "${STR_TMP_JSON_PATH}"

#文字でも一文字ならOK
# It's okay if it's 1 character
#	/bin/echo "{\"emoji\":\"済\"}" > "${STR_TMP_JSON_PATH}"
#	/bin/echo "{\"emoji\":\"‼\"}" > "${STR_TMP_JSON_PATH}"
#	/bin/echo "{\"emoji\":\"􀣺\"}" > "${STR_TMP_JSON_PATH}"
#	/bin/echo "{\"emoji\":\"✓\"}" > "${STR_TMP_JSON_PATH}"
#	/bin/echo "{\"emoji\":\"★\"}" > "${STR_TMP_JSON_PATH}"

#JSONをバイナリーで読み込み xattrで値をセットします
# Read the JSON in binary and set the value using xattr
/usr/bin/xattr -x -w com.apple.icon.folder\#S "$(/usr/bin/xxd -p "${STR_TMP_JSON_PATH}" | tr -d '\n')" ~/Desktop/ColorFolder

#更新します
# Update
/usr/bin/SetFile -a C ~/Desktop/ColorFolder

#PLISTを作ります
# Create a PLIST
# The sample [ブルー] uses a Japanese label name; in English, it will probably appear in [Blue]
#JA:"ラベル無し", "グレイ", "グリーン", "パープル", "ブルー", "イエロー", "レッド", "オレンジ"
#EN:"None", "Gray", "Green", "Purple", "Blue", "Yellow", "Red", "Orange"
#ターミナルへコマンドをペーストする場合は!をエスケープ
#If you paste commands into the Terminal, make sure to escape !.
#For terminal
#	/bin/echo "<\!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>ブルー</string></array></plist>" > "${STR_TMP_PLIST_PATH}"
#For Script
/bin/echo "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>ブルー</string></array></plist>" > "${STR_TMP_PLIST_PATH}"

#PLISTをバイナリーで読み込み xattrで値をセットします
# Read the PLIST in binary and set the value using xattr
/usr/bin/xattr -x -w com.apple.metadata:_kMDItemUserTags "$(/usr/bin/xxd -p "${STR_TMP_PLIST_PATH}" | tr -d '\n')" ~/Desktop/ColorFolder

#更新します
# Update
/usr/bin/SetFile -a C ~/Desktop/ColorFolder

#########################
#For SF Symbols
#フォルダを作ります
# Create a folder
/bin/mkdir -p ~/Desktop/ColorFolderSF

STR_TMP_DIR_PATH=$(/usr/bin/mktemp -d)
STR_TMP_JSON_PATH="${STR_TMP_DIR_PATH}/tag.json"
STR_TMP_PLIST_PATH="${STR_TMP_DIR_PATH}/label.plist"

#JSONを作ります
# Create a JSON file with the emoji you want to render
/bin/echo "{\"sym\":\"applescript.fill\"}" > "${STR_TMP_JSON_PATH}"

#JSONをバイナリーで読み込み xattrで値をセットします
# Read the JSON in binary and set the value using xattr
/usr/bin/xattr -x -w com.apple.icon.folder#S "$(/usr/bin/xxd -p "${STR_TMP_JSON_PATH}" | tr -d '\n')" ~/Desktop/ColorFolderSF

#更新します
# Update
/usr/bin/SetFile -a C ~/Desktop/ColorFolderSF

#PLISTを作ります
# Create a PLIST
# The sample [ブルー] uses a Japanese label name; in English, it will probably appear in [blue]
#ターミナルへコマンドをペーストする場合は!をエスケープ
#If you paste commands into the Terminal, make sure to escape !.
#For terminal
#	/bin/echo "<\!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>ブルー</string></array></plist>" > "${STR_TMP_PLIST_PATH}"
#For Script
/bin/echo "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><string>ブルー</string></array></plist>" > "${STR_TMP_PLIST_PATH}"



#PLISTをバイナリーで読み込み xattrで値をセットします
# Read the PLIST in binary and set the value using xattr
/usr/bin/xattr -x -w com.apple.metadata:_kMDItemUserTags "$(/usr/bin/xxd -p "${STR_TMP_PLIST_PATH}" | tr -d '\n')" ~/Desktop/ColorFolderSF

#更新します
# Update
/usr/bin/SetFile -a C ~/Desktop/ColorFolderSF


exit 0

Hope you find it helpful!

The symbol names for SF Symbols can be found in the SF Symbols app

2 Likes