はじめに
最近 Qiita で話題になってる。 OS X 10.10 Yosemite からの新機能だそうで、
今まで AppleScript で書いていたような機能が JavaScript で書けるようだ。面白い。
書いたもの
Google Chrome の全 Window の全タブを巡って、 TSV 形式で出力する。
chromeurls
#!/usr/bin/env osascript -l JavaScript
Application("Google Chrome").windows().forEach(function (window) {
window.tabs().forEach(function (tab) {
var url = tab.url()
, name = tab.name()
;
console.log(url + "\t" + name);
});
});
なんとなく、このポジションには Swift の方が相応しそうな雰囲気もする…。
AppleScript 版
せっかくなので AppleScript で書いた ver
chromeurls
#!/usr/bin/env osascript
set o to ""
tell application "Google Chrome"
repeat with w in windows
repeat with t in (tabs of w)
set o to (o & (url of t) & "\t" & (name of t) & "\n")
end repeat
end repeat
end tell
return text 1 thru -2 of o
使い方
$ chmod +x chromeurls
$ ./chromeurls
~/.bin にでも置いて PATH 通しておこう。