お前らのTouch Barはダサいという記事に感化されてBetterTouchTool (BTT)を導入しました。
上の記事ではSpotifyの再生中の曲名を表示していましたが、私はブラウザ版Amazon Music派なのでその曲名を表示させるようにしたいと思います。
やりたいこと
- Web版Amazon Musicで再生中の曲名を表示するウィジェットを配置
- Amazon Musicを開いていないときにウィジェットをタップするとAmazon Musicを新しいタブで開く
やってみた
BTTの設定を開いてTouch Barから[+Widget/Gesture]をクリックします。
適当な名前を[Name]に入力してスクリプトの入力エリアに以下のスクリプトを入力して[Save]をクリックします。[Appearance&Setting]で適当なアイコンもセットしておきます。
getTitle.applescript
if application "Google Chrome" is running then
tell application "Google Chrome"
repeat with w in windows
set i to 1
repeat with t in tabs of w
if URL of t starts with "https://music.amazon.co.jp" then
set song_title to execute t javascript "document.getElementById('dragonflyTransport').getElementsByClassName('trackTitle')[0].getElementsByTagName('a')[0].getAttribute('title');"
return song_title
end if
set i to i + 1
end repeat
end repeat
return "-"
end tell
end if
これで再生中の曲名が表示されます。
続いてAmazon Musicを開いていない時にウィジェットをタップすると新しいタブでAmazon Musicを開く処理を追加します。
追加したウィジェットの[Predefined Action]から[Run Apple Script(async...]をクリックします。
スクリプトの入力エリアが表示されるので以下のスクリプトを入力して[Save]をクリックします。
launchAM.applescript
tell application "Google Chrome"
repeat with w in windows
set i to 1
repeat with t in tabs of w
if URL of t starts with "https://music.amazon.co.jp" then
return
end if
set i to i + 1
end repeat
end repeat
do shell script "open -a Google\\ Chrome https://music.amazon.co.jp/home"
return
end tell