Last active
November 9, 2018 21:44
-
-
Save tvwerkhoven/aa0e64d4c2d27830462ffdd01da38043 to your computer and use it in GitHub Desktop.
spotify kodi startup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# spotify-kodi startup script | |
# | |
# Start spotify, wait for display, start kodi, bring kodi window into focus (again) | |
# | |
# # USAGE | |
# 1. Install somewhere (e.g. /snap/bin/) | |
# 2. Run as startup item on Linux | |
# | |
# # ABOUT | |
# | |
# This script solves two problems I had when automatically starting spotify and kodi on my HTPC Intel NUC: | |
# 1. spotify steals focus from kodi | |
# 2. kodi gives a black screen when started before TV is on | |
# | |
# # spotify stealing focus | |
# | |
# Linux spotify cannot start minimized. To fix this, I start both spotify and kodi, and after a while, | |
# I run wmctrl to give kodi focus back. | |
# | |
# # Kodi shows black screen | |
# | |
# On my Intel NUC connected via HDMI to my Onkyo receiver connected via HDMI to my Samsung TV, | |
# if Kodi starts when the TV is not on yet, it 'hangs' in a black screen from which it will | |
# not recover, requiring a restart of Kodi. Other programs (E.g. desktop, spotify) don't have | |
# this issue. I've also not found any Kodi setting that fixes this. | |
# | |
# The following did NOT work: | |
# - Blank other displays off (not working) | |
# - Force video out to HDMI-1 instead of ‘default’ (does not work) | |
# - Boot into kodi directly as window manager (does not work | |
# | |
# As a work-around, I use xrandr to check the display settings, where I have unique output for | |
# HDMI-1 for three different possible states: | |
# 1. Receiver off, TV off (or on): HDMI-1 disconnected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 0mm x 0mm | |
# 2. Receiver on, TV off: HDMI-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 708mm x 398mm | |
# 3. Receiver on, TV on: HDMI-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 160mm x 90mm | |
# | |
# The script below runs xrandr until it sees the tv is on, and then starts kodi as usual. | |
# Start spotify | |
echo "spotify" | |
/snap/bin/spotify 1> /dev/null 2>&1 & | |
sleep 3 | |
# Stat kodi second, but only when TV and receiver are on, using xrandr --query. Sleep until TV and Receiver are on | |
waittime=0 | |
echo "waiting loop" | |
while [[ -z $(xrandr --query | grep HDMI-1 | grep "160mm x 90mm") ]]; do | |
echo "xrandr:" $(xrandr --query | grep HDMI-1 | grep "160mm x 90mm") | |
sleep 1 | |
waittime=$(($time + 1)) | |
done | |
# TV and receiver are on here, start Kodi | |
echo "Kodi" | |
/usr/bin/kodi 1> /dev/null 2>&1 & | |
# Ensure kodi has focus (over spotify) -- sleeping could be superfluous if waittime >> 0, but this solution is simpler | |
sleep 3 | |
wmctrl -a "Kodi" | |
sleep 6 | |
wmctrl -a "Kodi" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment