TextEdit でテキストを書くときにエラーを回避する方法は、それがテキスト エディターであることを覚えておくことです。エラーを生成せずにテキスト ドキュメントを作成して保存する方法は既にわかっています。アクセスのために (エラーが発生しやすい) open を使用する必要はありません。(エラーが発生しやすい) シェル スクリプトを使用する必要はありません。あなたがしなければならないことは、TextEdit に依頼して、好きな内容でテキスト ドキュメントを作成し、好きな場所に保存するだけです。TextEdit は、ファイル アクセス エラー (アクセスのために開くなど) を生成したり、誤ってフォルダーを上書きしたり (シェル スクリプトなど) することなく、それを行う方法を知っています。
tell application "TextEdit"
activate
set theDesktopPath to the path to the desktop folder as text
set file_URLs_content to "HEEEELLOOOOOO"
make new document with properties {text:file_URLs_content}
save document 1 in file (theDesktopPath & "file.txt")
close document 1
end tell
この方法の利点は、記述が高速で簡単であること、エラーが発生しにくいこと、出力として得られるテキスト ファイルが、TextEdit で手動で作成したテキスト ファイルと同じプロパティを持つこと、およびスクリプトを簡単に作成できることです。他のアプリを含むように拡張されました。たとえば、テキスト コンテンツが別のアプリまたはクリップボードから取得され、テキスト ファイルが別のアプリで開かれたり、保存後にメールで送信されたりする可能性があります。
AppleScript の最も基本的な機能は、この方法で Mac アプリにメッセージを送信することです。PNG を JPEG に変換する場合は、AppleScript で PNG デコーダーと JPEG エンコーダーを記述せず、PNG ファイルを開いてアクセスし、バイト単位で読み取り、JPEG をバイト単位でエンコードします。PNG 画像を開き、JPEG として特定のファイルの場所にエクスポートするように Photoshop に指示するだけです。「open for access」コマンドは、読み書きするアプリがないファイルを読み書きするための最後の手段です。「do shell script」コマンドは、コマンド ライン アプリを組み込むためのものです。たとえば、Perl で正規表現を実行するなど、その作業を行うための Mac アプリがない場合に使用します。テキストファイルを扱うだけなら、TextEdit だけでなく、