8
3

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.

Touch Barに再生中のAmazon Musicの曲名を表示

Last updated at Posted at 2018-10-15

お前らのTouch Barはダサいという記事に感化されてBetterTouchTool (BTT)を導入しました。
上の記事ではSpotifyの再生中の曲名を表示していましたが、私はブラウザ版Amazon Music派なのでその曲名を表示させるようにしたいと思います。

やりたいこと

  • Web版Amazon Musicで再生中の曲名を表示するウィジェットを配置
  • Amazon Musicを開いていないときにウィジェットをタップするとAmazon Musicを新しいタブで開く

やってみた

BTTの設定を開いてTouch Barから[+Widget/Gesture]をクリックします。
Monosnap 2018-10-15 19-45-58.png

[Run Apple Script....]をクリック
Monosnap 2018-10-15 19-46-56.png

適当な名前を[Name]に入力してスクリプトの入力エリアに以下のスクリプトを入力して[Save]をクリックします。[Appearance&Setting]で適当なアイコンもセットしておきます。
Monosnap 2018-10-15 19-48-54.png

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...]をクリックします。
Monosnap 2018-10-15 19-49-18.png

スクリプトの入力エリアが表示されるので以下のスクリプトを入力して[Save]をクリックします。
Monosnap 2018-10-15 19-51-41.png

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

完成!

ezgif.com-crop.gif

8
3
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
8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?