Skip to content

Instantly share code, notes, and snippets.

@stekern
Last active May 25, 2019 13:14
Show Gist options
  • Save stekern/bfafd86014e5b32a422eb4e61e39365a to your computer and use it in GitHub Desktop.
Save stekern/bfafd86014e5b32a422eb4e61e39365a to your computer and use it in GitHub Desktop.
Seek a Spotify track from the command-line
#!/usr/bin/env bash
#
# Copyright (C) 2019 Erlend Ekern <dev@ekern.me>
#
# Distributed under terms of the MIT license.
# # # # # # # # # # # # # # # # #
# A script for seeking a currently playing Spotify track using the command-line
# # # # # # # # # # # # # # # # #
# The x-and y-coordinates need to be adjusted according to your screen resolution
# The default values work for a 1920x1080px screen
# Corresponds to the y-coordinate of the Spotify seekbar
y=1060
# Set x-coordinate for different seeking positions
if [ $1 = "left" ]; then
x=740
elif [ $1 = "middle" ]; then
x=960
elif [ $1 = "right" ]; then
x=1180
else
echo "Usage: $0 left|middle|right"
exit 1
fi
# Get id of current window
current_window_id="$(xdotool getactivewindow)"
# Search for Spotify window
target_window_id="$(wmctrl -l -x | grep spotify\.Spotify | head -1 | sed -r 's/^(\w+)\s*.*$/\1/g')"
if [ -z "$target_window_id" ]; then
echo "$0: Could not find Spotify window"
exit 1
fi
# Make the Spotify window fullscreen
xdotool windowsize "$target_window_id" 100% 100%
# Focus the Spotify window, click the seekbar and restore previous mouse position
xdotool windowactivate --sync "$target_window_id" mousemove "$x" "$y" click 1 mousemove restore
# Restore focus to the previous window
xdotool windowactivate "$current_window_id"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment