Skip to content

Instantly share code, notes, and snippets.

@KenshoFujisaki
Created August 9, 2020 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KenshoFujisaki/71a1d3e0803eb8777bf757209a34751c to your computer and use it in GitHub Desktop.
Save KenshoFujisaki/71a1d3e0803eb8777bf757209a34751c to your computer and use it in GitHub Desktop.
AppleScriptでGoogleChrome拡張ボタンを押下するテスト
-- cf. https://forum.keyboardmaestro.com/t/clicking-specific-chrome-extension-buttons/11950/17
-- GoogleChromeでのイベント名取得確認
tell application "Google Chrome"
activate
delay 0.3
end tell
tell application "System Events"
tell front window of (first application process whose frontmost is true)
set uiElems to entire contents
end tell
end tell
-- GoogleChromeで現在タブにて「Video Downloader Professional」を名称マッチでボタン押下する
tell application "Google Chrome"
activate
delay 0.3
end tell
tell application "System Events"
tell process "Google Chrome"
tell (first window whose subrole is "AXStandardWindow")
tell group 1
tell (first button whose name contains "Video Downloader")
click
--perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
@KenshoFujisaki
Copy link
Author

GoogleChrome拡張を用いた動画ダウンロードをAppleScriptで自動化

-- Chromeを開く
tell application "Google Chrome"
	activate
	delay 0.3
end tell

-- Chrome拡張「Stream Recorder」を開く( https://www.hlsloader.com/ja/index.html )
tell application "System Events"
	tell process "Google Chrome"
		tell (first window whose subrole is "AXStandardWindow")
			tell group 1
				tell (first button whose name contains "ストリーム")
					click
				end tell
			end tell
		end tell
	end tell
end tell

delay 2

-- Chrome拡張「Stream Recorder」で動画がダウンロードされるのを待ち、ダウンロード可能になったらダウンロードする。
tell application "Google Chrome"
	tell window 1
		tell active tab
			execute javascript "var id = setInterval(function(){if(document.getElementsByClassName('saveButton')[0].style.display != 'none'){document.getElementsByClassName('saveButton')[0].click();clearInterval(id);}}, 1000);"
		end tell
	end tell
end tell

delay 3

-- ポップアップのFinderで「保存」ボタンを押す
tell application "System Events"
	tell front window of (first application process whose frontmost is true)
		tell sheet 1
			tell (first button whose name contains "保存")
				click
			end tell
		end tell
	end tell
end tell

@KenshoFujisaki
Copy link
Author

YosemiteからAppleScriptの代わりにJavascript(JXA)が使えるようになっている
あまり情報がないけれど…
https://highmoon-miyabi.net/blog/2017/04/14_000443.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment