LoginSignup
20
21

More than 5 years have passed since last update.

OS X で Google Chrome の「今開いてる URL とタイトルを全て取得」

Last updated at Posted at 2015-02-16

はじめに

最近 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 通しておこう。

20
21
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
20
21