日々適当

hibitekitou

クリップボードの内容をテキストファイルで保存する

mac |2022-05-16

仕事で素材をもらった時、その素材に関する指示をメールなどで文章でもらいます。そうするとその素材を保管するフォルダの中にその文章もテキストファイルとして保存するのですけど、保存したい文章をコピー→テキストエディタにペースト→それをフォルダに保存、って手順となり面倒です。

ちょっとでも楽にならないかなぁと作ったAppleScript。Finderのスクリプトフォルダに保存して、スクリプトメニューから実行するようにしました。

素材ファイルを保存したフォルダを開いておいて、保存したい文章をコピー→Finderでスクリプト実行、です。汎用性を持たせるためにファイル名は日付けにしてあるけど、使う機会はこの用途しかないから、単に「メール.txt」とかいう名前で保存するようにしてやってもいいかもしんない。

set cbString to clipboard info for string
if cbString ≠ {} then
	set copiedString to the clipboard
end if

tell application "Finder"
	if exists Finder window 1 then
		set curDir to POSIX path of (target of Finder window 1 as Unicode text)
	else
		set curDir to POSIX path of (desktop as alias as Unicode text)
	end if
end tell

set fileName to do shell script "date \"+%y%m%d%H%m\""
set fileName to fileName & ".txt"

set filePath to (POSIX path of curDir) & "/" & fileName

do shell script "touch " & filePath

delay 0.1

try
	set myFile to open for access (filePath as POSIX file) with write permission
	write copiedString to myFile
	close access myFile
end try
コメント ( 0 )|Trackback ( )
  ・