5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Finderでファイルサイズを棒グラフ表示する

Last updated at Posted at 2021-03-01

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.
ScreenShot

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?