「コマンド/osascript」の版間の差分
提供: MacWiki
(→shebang) |
(→shebang) |
||
行36: | 行36: | ||
== shebang == | == shebang == | ||
− | (間接的に)shebangを実現 | + | 通常の流儀で書けばよい. |
+ | |||
+ | * Leopard(10.5)からはshebang行も解釈されるようになりました。 | ||
+ | |||
+ | $ cat astest | ||
+ | #!/usr/bin/osascript | ||
+ | tell application "iTunes" to play | ||
+ | beep 3 | ||
+ | |||
+ | |||
+ | |||
+ | ===(間接的に)shebangを実現 === | ||
+ | MacOSX 10.4 以前ではこちらが必要とのこと | ||
http://qz.tsugumi.org/AppleScript%252Fosascript.html | http://qz.tsugumi.org/AppleScript%252Fosascript.html | ||
行46: | 行58: | ||
cat "$1" | (read;/usr/bin/osascript - "$@") | cat "$1" | (read;/usr/bin/osascript - "$@") | ||
$ | $ | ||
− | |||
− | |||
== Wiki内の関連ページ == | == Wiki内の関連ページ == |
2009年10月19日 (月) 02:40時点における版
概要
AppleScript を実行するためのコマンドです。
- 場所: /usr/bin/osascript
- OS X のバージョン:Mac OS X 10.4
使い方
osascript <file>
osascript -e
osascript は指定されたファイルか、コードを AppleScript として実行します。 AppleScript ファイルをコマンドラインから呼び出せる他、Shell script と組み合わせて利用することも可能です。
-- -- sleep.scpt: sleep immediately -- tell application "Finder" sleep end tell
例えば、上のようなファイルを用意して、次のコマンドを実行すると、 30 分後に Mac をスリープさせることができます。
$ sleep 1800 && osascript sleep.scpt
オプション
-e <code>
<code> 部分の AppleScript コードを実行します。perl や ruby の -e オプションと使用方法は同じです。
osascript -e 'tell application "Finder" to activate'
shebang
通常の流儀で書けばよい.
- Leopard(10.5)からはshebang行も解釈されるようになりました。
$ cat astest #!/usr/bin/osascript tell application "iTunes" to play beep 3
(間接的に)shebangを実現
MacOSX 10.4 以前ではこちらが必要とのこと http://qz.tsugumi.org/AppleScript%252Fosascript.html
#!/usr/local/bin/osas tell application "iTunes" to play
$ cat /usr/local/bin/osas #!/bin/sh cat "$1" | (read;/usr/bin/osascript - "$@") $