4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Macトリビア】Script Editorを起動するURLスキーム

Last updated at Posted at 2015-02-23

applescript://で始まるリンクによってScript Editorを起動させることができます。

任意のソースを入力した状態で起動させることも可能です。
ソースをURLエスケープして「script」属性として渡します。

試しに以下のURLをMacのブラウザのアドレスバーにコピペしてみてください。

applescript://com.apple.scripteditor?script=tell+application+%22System+Events%22+to+display+alert+%22hello%22%0A

(残念ながらQiitaではapplescript://から始まるリンクを作成できません。)

URLの作成手順

ソースを書きます。

ダイアログ表示するだけのAppleScript
tell application "System Events" to display alert "hello"

AppleScriptでもJavaScriptでも構いません。

ですがユーザーのデフォルト設定で起動するので、JavaScript書いてもAppleScriptの設定で起動されたり、逆も然り。

適当にURLエスケープしていきます。

適当にURLエスケープ
$ echo 'tell application "System Events" to display alert "hello"' | ruby -r cgi -e 'puts CGI.escape($stdin.read)'
エスケープ後のソース
tell+application+%22System+Events%22+to+display+alert+%22hello%22%0A

URLエスケープしたソースを
applescript://com.apple.scripteditor?script=
の最後に付け足して終わり。

完成
applescript://com.apple.scripteditor?script=tell+application+%22System+Events%22+to+display+alert+%22hello%22%0A

Safari, Chrome, FireFoxなどの各種ブラウザやopenコマンド等で使用可能です。
今回は一行のソースでしたが、複数行も可。

追加属性

action属性に以下の文字列を設定することで、ソースの入力位置を変更できる・・・
らしいですが、動きませんでした。

動作
new 新しいウィンドウを作成してコードを入力する (デフォルト)
insert 既存のウィンドウのカーソル位置にコードを追加する
append 既存のウィンドウの最後の位置にコードを追加する
insertの例
applescript://com.apple.scripteditor?action=append&script=tell...

使い道

不明

参考

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?