LoginSignup
1
1

macOSでFinderの右クリックから新規テキストファイルを作成する

Last updated at Posted at 2023-07-07

macOSのFinderでは、Windowsのエクスプローラーのように右クリックメニューから直接新規テキストファイルを作成する機能はデフォルトでは提供されていません。しかし、AutomatorとAppleScriptを使用すれば、この機能をカスタムで追加することができます。

以下にその手順を示します。

1. Automatorを開く

まずは、Applications フォルダから Automator を開きます。
(cmd + spaceで検索)

2. 新規ドキュメントを作成

Automatorの起動画面が表示されたら、「クイックアクション」をクリックします。
スクリーンショット 2023-07-08 0.14.26.png

3. クイックアクションの詳細を設定

次に、右側の詳細設定エリアで以下のように設定します。

「ワークフローが受け取る現在の項目」: ファイルまたはフォルダ
「検索対象」: Finder

4. AppleScriptを追加

左側のライブラリから「ユーティリティ」を選択し、「AppleScriptを実行」を右側のワークフローエリアにドラッグ&ドロップします。

5. AppleScriptを記入

AppleScriptのコードエリアに以下のスクリプトをコピー&ペーストします。

applescript
Copy code
on run {input, parameters}
    tell application "Finder"
        set currentPath to insertion location as text
        set theDate to current date
        set yearString to year of theDate as string
        set monthString to my zeroPad(month of theDate as integer as string)
        set dayString to my zeroPad(day of theDate as string)
        set hourString to my zeroPad(hours of theDate as string)
        set minuteString to my zeroPad(minutes of theDate as string)
        set secondString to my zeroPad(seconds of theDate as string)
        set newFileName to yearString & monthString & dayString & "_" & hourString & "." & minuteString & "." & secondString & ".txt"
        set newPath to POSIX path of currentPath & newFileName
        make new file at currentPath with properties {name:newFileName}
    end tell
end run

on zeroPad(num)
    if num's length < 2 then
        return "0" & num
    else
        return num
    end if
end zeroPad

設定すると、以下のようになるはずです。
スクリーンショット 2023-07-08 0.28.07.png

6. クイックアクションを保存

「ファイル」メニューから「保存」を選択し、クイックアクションに名前をつけて保存します(例:「New Text File」)。

これで設定は完了です。Finderで右クリックすると「クイックアクション」の下に先ほど作成した「New Text File」が表示され、これを選択すると新規テキストファイルが作成されます。

なお、このテキストファイルの名前は「yyyymmdd_hh.mm.ss.txt」の形式になります。
(ファイル名重複するとエラーになるため)
※注意事項として、localの環境では動きますが、iCloudドライブなどでは、右クリックしてもメニューが出てきません。

以上で、Finderで直接新規テキストファイルを作成する環境が整いました。
お試しください。

1
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
1
1