Sending Chrome Tabs to get_iPlayer on MacOS via the Command Line.

It’s a pretty simple command line…

osascript -e{'set text item delimiters to linefeed','tell app"google chrome"to url of tabs of windows as text'} | grep -E 'www.bbc.co.uk/programme|www.bbc.co.uk/iplayer/episode' | xargs -t -n1  get_iplayer --pid-recursive

…and it seems rather resilient. This should work with an out of the box install of MacOS 11.* with a default ‘get_iplayer‘ instance but without any additional third party utilities.

Breakdown

osascript -e{'set text item delimiters to linefeed','tell app"google chrome"to url of tabs of windows as text'}

‘osascript’ is the command line Applescript interpreter. It this case we’re using it to ask Chrome to list the URLs for all tabs in all open windows and to list each URL on a newline.

grep -E 'www.bbc.co.uk/programme|www.bbc.co.uk/iplayer/episode'

This filters out all of the URLS that are unrelated to iplayer programs.

xargs -t -n1  get_iplayer --pid-recursive

Tells xargs to…

  1. Echo the command to be run
  2. Treat each newline separated URL as a parameter and to…
  3. Run get_iplayer –pid-recursive for each URL

All of this, of course, is chained together using the ‘|’ operator.