After some initial test of Applescript control google chrome player in last repo QtControlAppleScript_test. I decide open a new repo to continue the more features.
Started this project because while using Home Assistant to control my home, I found that I was missing a device for simple control of my playback computer. Since I use a Mac Mini in my home that is directly connected to the NEC projector, I can currently only switch the NEC projector on and off with Home Assistant, but not the player (my Mac Mini).
So I decided to do some tools of controlling my player in a simple way.
A small tool made of Qt, using Apple Script to simulate keyboard control. A part of my SmartHomeTools.
In AppleScript part, simply using the System Event's "KeyStroke" to simulate a keyboard activity. And then, tell process Google Chrome. So that if you are already watching a Video on web site. It can control the video play/pause. Just like you are pressing the "Space" key to play or pause this video.
(for all dear contributors, I have not test on NetFlix. If you have NetFlix account and prefer to test this tool, please tell me any result or issues, thanks a lot ! )
This software is used as a part of my own SmartHome Tool with Home Assistant.
-
Download .dmg package from last release version.
-
Mount .dmg image on macOS(which you prefer to control) and drag .app file to your local application folder (or anywhere you want)
-
Open this .app file
-
Open your Chrome and choose your favorite Youtube video to test.
-
Click "Play/Pause" to test if everything runs well.
-
Normally you will be noticed by macOS, allow this application to control (or it will not work)
-
If the video has been successful play/pause controlled. You can test other functions if those buttons works as description.
-
Change the mode from "Local mode" to "Remote mode", and select "Server Side" instead of "Client Side"
-
Generally, you will be noticed to allow income trafic of firewall of macOS.
-
Then Open terminal.app, use code below to test if the Server side has been successfully deployed or not.
curl http://localhost:16250/run/0/
- If the video in Chrome has been successful play/pause controlled. The deploy server side part finished.
-
It is assumed that HomeAssistant already exists on your home LAN and is working fine.
-
Add code below to your configuration.yaml file (or any of your custom .yaml file)
# commandline
shell_command:
smt_playorpause: curl http://Your-ServerSide-IPAddress:16250/run/0/
smt_rwd: curl http://Your-ServerSide-IPAddress:16250/run/1/
smt_fwd: curl http://Your-ServerSide-IPAddress:16250/run/2/
smt_volup: curl http://Your-ServerSide-IPAddress:16250/run/3/
smt_voldown: curl http://Your-ServerSide-IPAddress:16250/run/4/
smt_nextvideo: curl http://Your-ServerSide-IPAddress:16250/run/5/
smt_fullscreen: curl http://Your-ServerSide-IPAddress:16250/run/6/
smt_theater: curl http://Your-ServerSide-IPAddress:16250/run/7/
smt_volmute: curl http://Your-ServerSide-IPAddress:16250/run/8/
smt_closetab: curl http://Your-ServerSide-IPAddress:16250/run/9/
smt_reopentab: curl http:/Your-ServerSide-IPAddress:16250/run/10/
-
Save & Reload configuration of your Home Assistant
-
Than add each command in "Script" part of your Home Assistant. Or if you prefer to use YAML to add "Script", try code below
#an example for Play/Pause script
alias: Play/Pause
sequence:
- service: shell_command.smt_playorpause
data: {}
mode: single
icon: mdi:play-pause
#yaml for lovelace above
type: vertical-stack
cards:
- type: horizontal-stack
cards:
- show_name: false
show_icon: true
type: button
tap_action:
action: toggle
entity: script.smt_rewind
- show_name: false
show_icon: true
type: button
tap_action:
action: toggle
entity: script.smt_playorpause
- show_name: false
show_icon: true
type: button
tap_action:
action: toggle
entity: script.smt_fwd
- type: horizontal-stack
cards:
- show_name: false
show_icon: true
type: button
tap_action:
action: toggle
entity: script.smt_volumeminus
- show_name: false
show_icon: true
type: button
tap_action:
action: toggle
entity: script.smt_volumeplus
- show_name: false
show_icon: true
type: button
tap_action:
action: toggle
entity: script.smt_volumemute
- type: horizontal-stack
cards:
- show_name: false
show_icon: true
type: button
tap_action:
action: toggle
entity: script.smt_theatermode
- show_name: false
show_icon: true
type: button
tap_action:
action: toggle
entity: script.smt_playerfullscreen
- show_name: false
show_icon: true
type: button
tap_action:
action: toggle
entity: script.smt_nextvideo
- type: horizontal-stack
cards:
- show_name: true
show_icon: false
type: button
tap_action:
action: toggle
entity: script.smt_closetab
- show_name: true
show_icon: false
type: button
tap_action:
action: toggle
entity: script.reopentab
- Add API server function. So it support directly use the http request to control.
- Add more features
Next step will create the remote version.
Maybe this tool will provide a webAPI, and sinply http request will control the play / pause instead using button.
- Apple macOS 10.15.7 Catalina or macOS 13.1 Ventura (only test on these 2 version) (intel silicon only)
- Google Chrome version 108 or newer version
- Apple macOS 10.15.7 Catalina (intel silicon)
- Qt Community Version (Clang 6.4.2) -- Remark ! Since Qt 6.4, Qt += httpserver has been supported !
License LGPL v3 (Development with Qt Community version)