Finderの表示では、個々のファイルの大きさが直感的にとらえられない。サイズでソートすると今度はどのファイルが新しいのかがわからない。そこで、ファイルサイズをComment欄に棒グラフで表示するだけのスクリプトを作った。
The Finder's display does not intuitively capture the size of individual files. If you sort by size, you can't tell which file is newer. So I made a script that just displays the file size as a bar graph in the comment column.
# !/bin/bash
function sizebar_ () {
filepth="$1"
comment=$(mdls -r -nullMarker "" -n kMDItemFinderComment "$filepth" | sed -e 's:|*::' )
size=$(du -s "$filepth" | awk '{s=int(log($1)/log(2));for(i=0;i<s;i++)printf("|")}')
newcomm=$size$comment
/usr/bin/osascript -e "set filepath to POSIX file \"$filepth\"" \
-e "set the_File to filepath as alias" \
-e "tell application \"Finder\" to set the comment of the_File to \"$newcomm\""
}
# escape spaces in the file name
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in *
do
sizebar_ "$f"
done
IFS=$SAVEIFS
スクリプトを実行したディレクトリの全ファイルに、対数目盛の棒グラフが付加される。
A bar graph in log scale will be added to the commend fields of all files in the directory where the script was executed.