AppleScript メモ

Quick Edit Pencil

Finder

(新規作成)

Finder 最前面ウインドウのフォルダにテキストファイルを作成する

tell application "Finder"

if exists folder of the front window then

set i to folder of the front window

else

set i to desktop

end if

set p to quoted form of (POSIX path of (i as Unicode text))

set n to do shell script "date +%Y%m%d-%H%M%S.txt"

do shell script "touch " & p & n

end tell

サービスとして登録して、キーボードショートカット(cmd+ctrl+shift+N)を割り当ててみた。

削除の場合赤字touchrmにする。

do shell script "touch " & p & n

(追記,追加,編集)

[ AppleScript ] 変数の内容をテキストファイルに書き出すサンプル

デスクトップに「test.txt」と言う名前のファイルが存在しない場合、新規作成します。ファイルが既に存在していれば追記。

tell application "Finder"

set aText to ("日本語のサンプル文字列" & return)

set aTextFile to open for access ((desktop as text) & "test.txt") with write permission

set aEOF to get eof of aTextFile

try

writeaTextstarting at (aEOF + 1) toaTextFile

on error aErrorText

display dialogaErrorText

end try

close accessaTextFile

end tell


日本語を書き出す時、文字コードはどうなるんだろう?

 

 

Path

(ファイルパス,ファイル名,ディレクトリ,変換)

ファイルパスからファイル名や拡張子を自由に取り出す

AppleScript

自分自身のファイルパスを取得

path to me

--alias "Macintosh HD:Users:zari:Library:Scripts:test_path_to.me.scpt"

 

ファイル名を取得

tell application "Finder" to (path to me)'s name

--"test_path_to.me.scpt"

 

ディレクトリを取得

tell application "Finder" to (path to me)'s folder as text

--"Macintosh HD:Users:zari:Library:Scripts:"

 

UNIX形式のパスに変換

(path to me)'s POSIX path

--"/Users/zari/Library/Scripts/test_path_to.me.scpt"

 

AppleScript形式のパスに変換

POSIX file "/Users/zari/Library/Scripts/test_path_to.me.scpt"

--file "Macintosh HD:Users:zari:Library:Scripts:test_path_to.me.scpt"

 

application

(TextEdit)

新規文書 (ウィンドウ) を作成

set theText to "* " & ((current date) as string) & return -- 新規文書に書き込む文字列(ここでは日時)

tell application "TextEdit"

activate

if not (exists front document) then makenewdocument

if text of front document is "" then

set theDoc to front document

else

set theDoc to makenewdocument

end if

set text of theDoc to theText -- 文字列を書き込む

set properties of text of theDoc to {color:{65535, 0, 0}, size:12, font:"Osaka-Mono"} -- 文字のサイズなどを指定できる(この指定は維持されない)

end tell

Finderで選択中の画像ファイルを、新規文書 (ウィンドウ) を作成して貼付ける

tell application "Finder"

set theFiles to selection

end tell

set aFile to theFiles

set aPath to aFile as Unicode text


tell application "TextEdit"

activate

set NewDoc to (makenewdocument)

set name of front window to fname_ext

set text of NewDoc to return & return & return & aExif

makenewattachmentwith properties {file name:(aPath as alias)} at after the first character of document 1

end tell

 

サンプル集

このブログの人気の投稿

書字方向 横書方向変換スクリプト 左書きから右書きへ(コピペ用途)

PowerShellのGetDetailsOf メソッドでプロパティの詳細情報のID番号と項目名を列挙します

PowerShellで複数ファイルのプロパティを取得する方法(準備編)

簡単 YouTube動画をダウンロード、音声のみ保存する方法 2019

DOMノードオブジェクトを文字列に変換する

AppleScript 改行 コード 置換

PowerShellでJPG画像のリサイズとウォーターマーク画像との合成を同時に行う

Blender: 辺の長さを数値で指定するアドオン