从 shell 脚本在 OS X Finder 中用颜色标记文件 [英] Tagging files with colors in OS X Finder from shell scripts

查看:30
本文介绍了从 shell 脚本在 OS X Finder 中用颜色标记文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在 Mac OS X Finder 中用颜色标记文件和文件夹.有没有办法从 shell 脚本中做到这一点?

One can tag files and folders with a color in the Mac OS X Finder. Is there a way to do this from a shell script?

推荐答案

此 shell 脚本将文件或文件夹名称作为其第一个参数和标签索引(0 表示无标签,1 表示红色,...,7 表示gray) 作为第二个参数.

This shell script takes the file or folder name as its first argument and the label index (0 for no label, 1 for red, ..., 7 for gray) as its second argument.

#!/bin/sh
osascript -e "tell application \"Finder\" to set label index of alias POSIX file \"`cd -P -- "$(dirname -- "$1")" && printf '%s\n' "$(pwd -P)/$(basename -- "$1")"`\" to $2"

更直接的,如果$filename是一个带有要标注的文件或文件夹的绝对路径名的shell变量,而$label是一个带有标签索引号的shell变量,

More directly, if $filename is a shell variable with the absolute path name of the file or folder to be labeled and $label is a shell variable with the label index number,

osascript -e "tell application \"Finder\" to set label index of alias POSIX file \"$filename\" to $label"

是一个 shell 命令,用于为文件或文件夹分配标签.

is a shell command to assign the label to the file or folder.

这篇关于从 shell 脚本在 OS X Finder 中用颜色标记文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆