[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
#20251007 fixed Example
#20251013 I changed the way the PLIST file is created.

#########################
#For Emoji
#パスの指定
#Set File and Dir path
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"
#ユーザーのデスクトップにフォルダを作る
#make new folder on user desk top
STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
STR_DIR_PATH="/Users/${STAT_USR}/Desktop/ColorFolder"

#フォルダを作ります
# Create a folder
/bin/mkdir -p "${STR_DIR_PATH}"

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

#文字でも一文字ならOK
#たぶん SF Proに収録されている文字なら設定可能
# 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')" "${STR_DIR_PATH}"

#更新します
# Update
/usr/bin/SetFile -a C "${STR_DIR_PATH}"

#PLISTを作ります
# Create a PLIST
# The sample [ブルー] uses a Japanese label name; in English, it will probably appear in [Blue]
#EN
/bin/echo '["Blue"]' | /usr/bin/plutil -convert xml1 -o "${STR_TMP_PLIST_PATH}"  -
#JA
#/bin/echo '["ブルー"]' | /usr/bin/plutil -convert xml1 -o "${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')" "${STR_DIR_PATH}"

#更新します
# Update
/usr/bin/SetFile -a C "${STR_DIR_PATH}"

#########################
#For SF Symbols
#パスの指定
#Set File and Dir path
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"
#ユーザーのデスクトップにフォルダを作る
#make new folder on user desk top
STAT_USR=$(/usr/bin/stat -f%Su /dev/console)
STR_DIR_PATH="/Users/${STAT_USR}/Desktop/ColorFolderSF"

#フォルダを作ります
# Create a folder
/bin/mkdir -p "${STR_DIR_PATH}"

#JSONを作ります
# Create a JSON file with the SF Symbols Name  you want to render
/bin/echo "{\"sym\":\"applescript.fill\"}" > "${STR_TMP_JSON_PATH}"
#例
#Example
#	/bin/echo "{\"sym\":\"house.fill\"}" > "${STR_TMP_JSON_PATH}"
#	/bin/echo "{\"sym\":\"trash.slash\"}" > "${STR_TMP_JSON_PATH}"
#	/bin/echo "{\"sym\":\"textformat.characters.arrow.left.and.right\"}" > "${STR_TMP_JSON_PATH}"
#	/bin/echo "{\"sym\":\"externaldrive.connected.to.line.below.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')" "${STR_DIR_PATH}"

#更新します
# Update
/usr/bin/SetFile -a C "${STR_DIR_PATH}"

#PLISTを作ります
# Create a PLIST
# The sample [ブルー] uses a Japanese label name; in English, it will probably appear in [blue]
#EN
/bin/echo '["Blue"]' | /usr/bin/plutil -convert xml1 -o "${STR_TMP_PLIST_PATH}"  -
#JA
#/bin/echo '["ブルー"]' | /usr/bin/plutil -convert xml1 -o "${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')" "${STR_DIR_PATH}"

#更新します
# Update
/usr/bin/SetFile -a C "${STR_DIR_PATH}"


exit 0

Hope you find it helpful!

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

20251007 fixed Example
20251013 I changed the way the PLIST file is created.

3 Likes