AppleScriptは簡単なプログラムで様々なアプリケーションのコントロールが行え、 決まった手順の作業の繰り返しの時など非常に役立ちます。
AppleScript対応のアプリケーションはたくさんあるのですが、ほとんどの場合にマニュアル中ではAppleScriptからの使い方が解説されていないことや、AppleScriptの一般的な参考書が少ないのが欠点です。
AppleScriptをうまく使うと、コマンドの出力を別のコマンドの入力に用いるUnixのパイプ処理と同様のことができるようになり、なにかと便利です。以下にちょっと便利なAppleScriptのプログラムを紹介しましょう。
(使用環境:PM7600 & Mac OS.8 and AppleScript 1.1.2)
on open DropFiles repeat with aFile in DropFiles set FileHandler to open for access aFile set TextContents to read FileHandler close access FileHandler tell application "Eudora Pro 2.1.3-J" set NewMessage to make message at the end of mailbox "送信" set field "To" of NewMessage to "yasuda@eri.u-tokyo.ac.jp" set field "Subject" of NewMessage to "put_subject_here" set body of NewMessage to TextContents save NewMessage queue NewMessage connect with sending without checking quit application "Eudora Pro 2.1.3-J" end tell end repeat end open
on open DropFiles・・end open
の書式をもつAppleScriptは「実行専用で保存」という形式で保存してください。そうしないとDrag&Drop機能が働きません。
on open dropFiles repeat with aFile in dropFiles set FileHandler to open for access aFile set TextContents to read FileHandler close access FileHandler tell application "KaleidaGraph" SendData TextContents LoadPlotScript "HDdisk:KGScript" RunPlotScript end tell end repeat end open
on open DropFiles tell application "Fetch 3.0.1" make new transfer window at beginning with properties {hostname:"remote.host", userid:"yourID", password:"yourPassword"} open remote directory "targetDirectory_in_remotehost" repeat with AFile in DropFiles put into transfer window "your.remote.host" item AFile text format Text binary format Raw Data end repeat quit Application "Fetch 3.0.1" end tell end open
tell application "Finder" set FileHandler to open for access file ((path to desktop folder as text) & "My_mail") set TextContents to read FileHandler close access FileHandler end tell tell application "Eudora Pro 2.1.3-J" set NewMessage to make message at the end of mailbox "送信" set field "To" of NewMessage to "e-mail_address@domain" set field "Subject" of NewMessage to "put_subject_here" set body of NewMessage to TextContents save NewMessage queue NewMessage connect with sending without checking quit application "Eudora Pro 2.1.3-J" end tell tell application "Finder" delete the file ((path to desktop folder as text) & "My_mail") end tell
・レコード書き出し[記憶する,「My_mail」]
・AppleScriptを実行[ .......]
のように、連続実行させるように用いれば、ボタン一つでファイルメーカーの特定のレコードをメール送信することができるようになります。
tell application "Fetch 3.0.1" make new transfer window at beginning with properties {hostname:"remote.host", userid:"yourID", password:"yourPassword"} open remote directory "targetDirectory_in_remotehost" duplicate remote file "Name_of_TransferFile" to beginning of alias "Path_of_Folder_to_save" quit Application "Fetch 3.0.1" end tell
tell application "Fetch 3.0.1" make new transfer window at beginning with properties {hostname:"remote.host", userid:"yourID", password:"yourPassword"} open remote directory "targetDirectory_in_remotehost" delete remote file "Name_of_TransferFile" quit Application "Fetch 3.0.1" end tell
Script2の
delete remote file "Name_of_TransferFile"
は消去するファイル名を記入します。
これらの2つのAppleScriptをファイルメーカーのスクリプト中で、
・AppleScriptを実行[...Script1...]
・レコード取り込み[記憶する,「Name_of_TransferFile」]
・AppleScriptを実行[ ... Script2..]
のように、連続実行させるように用います。