LoginSignup
0
0

More than 5 years have passed since last update.

Spotlight コメントをファイル名の先頭に付加する AppleScript

Posted at

背景

これまで Mac だけで管理していた某ファイル群を NAS に移し,Windows マシンとも共有できるようにしたかったのですが,そこで問題になるのが「ファイルに付与していた Spotlight コメントどうしよう問題」です.Spotlight コメントをタグ的に使っていたので,これが消えてしまうと目当てのファイルを検索しづらくなってしまいます.

本題

今回は,Spotlight コメントをファイル名の先頭に付加することで強引な解決を図りました.あらかじめ Finder で対象のファイルを選択しておいて,下記の AppleScript を実行すると,ファイル名を [コメント]ファイル名.txt みたいな感じにリネームしてくれます.フォーマットが気に入らないときは7行目を編集してください.

例によって処理速度はあまり早くないので,まずは100ファイル位から,ちょっとずつ実行しましょう.

tell application "Finder"
    set theFiles to selection
    repeat with aFile in theFiles
        set comm to comment of aFile
        if not (comm = "") then
            set fileName to name of aFile
            set name of aFile to "[" & comm & "]" & fileName
        end if
    end repeat
end tell

おまけ

そもそも Spotlight コメントが消えてしまっていることがよくあります.
原因は不明ですが,下記サイトのスクリプトで復活できました.ありがとうございます!

★ 消えてしまったSpotlightコメントを復活させるアップルスクリプト | § 使って楽しいアップルスクリプト集 §


tell application "Finder"
    set slct to (selection)
    repeat with x in slct
        set thepath to POSIX path of (x as alias)
        set spcomment to (do shell script "mdls -name kMDItemFinderComment " & quoted form of thepath & "| awk -F\\\" '{print $2}'")
        if spcomment is "" then

        else
            set comment of x to spcomment
        end if
    end repeat
end tell
0
0
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
0
0