mixiユーザー(id:7593622)

2020年06月13日21:25

99 view

Mac Automator AppleScript でファイルの読み書き

Web検索しても、なんかわかりづらかったけれども、とりあえず、ファイルを読み込むのと書き出しのテストとしてはこんな感じ。

この例は、単純に「readtest.txt」の中身を全部読み出して、「writetest.txt」に書き出すというもの

前半のファイル読み込み部分だけ、Automatorの中のAppleScriptに組み込んだら、ちゃんとファイルから読み込んだ値で、ブラウザのテキストフィールドに入力できた。


set theReadFile to "/(フルパス)/readtest.txt"
open for access theReadFile without write permission
set theText to read theReadFile
close access theReadFile

set theWriteFile to "/(フルパス)/writetest.txt" as POSIX file
open for access theWriteFile with write permission
write theText to theWriteFile
close access theWriteFile


補足
・「read」(3行目)を使う場合は2行目(openの行)と4行目(closeの行)は
 無くても良い
・1行目に無くて、6行目にある「as POSIX file」は、UNIXでの形式のパス指定
 では付けるものらしいけれど、無くても問題無かったので、1行目は付けていない。
0 0

コメント

mixiユーザー

ログインしてコメントを確認・投稿する

<2020年06月>
 123456
78910111213
14151617181920
21222324252627
282930