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

查看:200
本文介绍了标记文件与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灰)作为其第二个参数。

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天全站免登陆