![[PukiWiki] [PukiWiki]](image/pukiwiki.png) 
 コマンドラインからiTunesを再生させる場合は以下のようにする。
osascript -e 'tell application "iTunes" to play'
例えばC言語の場合は以下のようにする。
#include <stdlib.h>
int main(void){
   system("osascript -e \'tell Application \"iTunes\" to play\'");
   return 0;
}
と思ったけどJavaだけは普通ではなかった。
Runtime.getRuntime().exec("osascript -e \'tell Application \"iTunes\" to play\'");
は、なぜか動かない。exec(String [])というメソッドを呼ばないといけないらしい。 ( http://www.peterfriese.de/running-applescript-from-java/ )
Runtime.getRuntime().exec({"osascript","-e","tell Application \"iTunes\" to play"});
でこれをtry catchすれば良い。
try{
    Runtime.getRuntime().exec({"osascript","-e","tell Application \"iTunes\" to play"});
}catch (Exception e) {}
int iTunes (String cmd) {
   int result=0;
   String tell = "tell Application \"iTunes\" to " + cmd; 
   String[] command = {"osascript","-e",tell};
   try{
     Runtime.getRuntime().exec(command);
     }catch (Exception e) { result = -1; }
  return result;
}
void setup(){
    iTunes("play");
}
void draw(){}
hoge.m4vという動画ファイルをQuick Time Playerでフルスクリーンで起動する方法
#!/usr/bin/osascript
tell application "QuickTime Player"
    set aMovie to open "/Volume/home/siio/hoge.m4v"
    present aMovie
    play aMovie
    activate
end tell
コマンドライン引数から動画ファイルを指定する方法(Apple Script版)
on run argv
    tell application "QuickTime Player"
        set aMovie to open (first item of argv)
        present aMovie
        play aMovie
        activate
    end tell
end run
コマンドライン引数から動画ファイルを指定する方法(シェルスクリプト版)
#!/bin/sh
echo "
tell application \"QuickTime Player\"
    set aMovie to open \"$1\"
    present aMovie
    play aMovie
    activate
end tell
" | osascript -
たとえばシェルスクリプトで
open /Users/siio/cat.jpg
とすると写真ファイルが「プレビューで」開く。以下では、これをGUIから実行してみる。
アプリケーション/ユーティリティのなかにある、Apple Scriptエディタ.app
を開いて、
do shell script "open /Users/siio/cat.jpg
またApple Scriptエディタの、メニューバーから、 「ファイル」「別名で保存」からアプリケーションを選択して保存すれば、ダブルクリックで起動するようになる。
ダブルクリックで起動したときに、ファイルダイアログを呼び出したかったら、 次のようにする。ここでは開くファイルの拡張子をjpgにしている。Apple Scriptでは、ディレクトリの区切りが/じゃなくて:だったりするので、UNIX形式に変換する必要がある。
set aFile to choose file with prompt "Open file to be edited" of type ("jpg")
set aFile_posix to POSIX path of aFile
do shell script "open " & aFile_posix
のように、
on open drop_item set aFile_posix to POSIX path of drop_item do shell script "open " & aFile_posix end open
とすればよい。
on open drop_items repeat with aFile in drop_items set aFile_posix to POSIX path of aFile do shell script "open " & aFile_posix end repeat end open
tell application "Numbers"
	activate
end tell
tell application "System Events"
	keystroke "this"
	keystroke tab
	keystroke "is"
	keystroke return
	key down {shift}
	keystroke "a test"
	key up {shift}
end tell