add play pause script to i3
This commit is contained in:
parent
a3fb4b29dc
commit
4fcaf9899b
Binary file not shown.
|
@ -0,0 +1,50 @@
|
|||
import subprocess
|
||||
|
||||
|
||||
def show_now_playing():
|
||||
id = ["-r", "3984938"]
|
||||
|
||||
try:
|
||||
status = subprocess.Popen(
|
||||
["playerctl", "status"],
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
now_playing = subprocess.Popen(
|
||||
["playerctl", "metadata", "--format", "{{artist}} | {{title}}"],
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
"dunstify",
|
||||
status.communicate()[0],
|
||||
now_playing.communicate()[0],
|
||||
]
|
||||
+ id
|
||||
)
|
||||
except:
|
||||
subprocess.run(["dunstify", "⏯ ", "🦗 nothing to see here..."] + id)
|
||||
|
||||
|
||||
def get_amixer_volume() -> int:
|
||||
s: str = str(subprocess.check_output(["amixer", "get", "Master"]))
|
||||
try:
|
||||
# turns the front left argument into an int
|
||||
return int(
|
||||
# the thing we're looking for is in the fifth line
|
||||
s.split(r"\n")[5]
|
||||
.strip()
|
||||
# and is the 4th word
|
||||
.split(" ")[4]
|
||||
.replace("[", "")
|
||||
.replace("]", "")
|
||||
.replace("%", "")
|
||||
)
|
||||
except:
|
||||
return -1
|
||||
|
||||
|
||||
def display_volume(volume: int):
|
||||
subprocess.call(
|
||||
["dunstify", "volume 蓼", "-h", "int:value:" + str(volume), "-r", "39489384"]
|
||||
)
|
|
@ -111,7 +111,7 @@ in
|
|||
m = "exec --no-startup-id amixer set Master toggle";
|
||||
c = "exec --no-startup-id kitty cmus";
|
||||
v = "exec --no-startup-id mpv";
|
||||
Space = "exec playerctl play-pause";
|
||||
space = "exec python3 /etc/nixos/i3/play_pause.py";
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
import subprocess
|
||||
import audiotools
|
||||
|
||||
try:
|
||||
subprocess.Popen(["playerctl", "play-pause"]).wait()
|
||||
audiotools.show_now_playing()
|
||||
except:
|
||||
pass
|
28
i3/volume.py
28
i3/volume.py
|
@ -1,35 +1,11 @@
|
|||
# script that changes the volume and then shows a notfication with it using dunst
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
|
||||
def get_amixer_volume() -> int:
|
||||
s: str = str(subprocess.check_output(["amixer", "get", "Master"]))
|
||||
try:
|
||||
# turns the front left argument into an int
|
||||
return int(
|
||||
# the thing we're looking for is in the fifth line
|
||||
s.split(r"\n")[5]
|
||||
.strip()
|
||||
# and is the 4th word
|
||||
.split(" ")[4]
|
||||
.replace("[", "")
|
||||
.replace("]", "")
|
||||
.replace("%", "")
|
||||
)
|
||||
except:
|
||||
return -1
|
||||
|
||||
|
||||
def display_volume(volume: int):
|
||||
subprocess.call(
|
||||
["dunstify", "volume 蓼", "-h", "int:value:" + str(volume), "-r", "39489384"]
|
||||
)
|
||||
|
||||
import audiotools
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("volchange")
|
||||
args = parser.parse_args()
|
||||
|
||||
subprocess.check_output(["amixer", "set", "Master", args.volchange])
|
||||
display_volume(get_amixer_volume())
|
||||
audiotools.display_volume(audiotools.get_amixer_volume())
|
||||
|
|
Loading…
Reference in New Issue