Finderからテキストファイルを新規作成する
WIndowsではエクスプローラーから空っぽのテキストファイルが作れるが、Macだとフォルダは作れてもファイルが作れないのを何とかしたい
https://gyazo.com/8b17c15f1e2dacf5110a2cee4fd14798
「フォルダ」を受け取り、検索対象は「Finder.app」を選択
「フォルダまたはファイル」の方が使いやすい(2025/1/25)
https://gyazo.com/3b41db778e4d0d4c3d77363b17e08931
AppleScriptの内容
code:appleScript.scpt
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 "名前未設定.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
*もともとのコードではタイムスタンプがファイル名に設定されていたが、「名前未設定」に書き換えた。
名前をつけて保存する。
「新規テキストファイル作成」とした
実行
Finderの下の方に表示されるフォルダ情報を右クリック
https://gyazo.com/a73374d148827fccfc4838f7c483de1f
「サービス」の中身
https://gyazo.com/8d1571b8ca598b0944b56d235e1fc385
「新規テキストファイル作成」を実行
https://gyazo.com/e8381b4b51f818a1d3bff48faa847960
無事できた(2025/1/23)。