Skip to content

Instantly share code, notes, and snippets.

@OKsign
Created August 26, 2020 08:39
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 OKsign/ecae02815e8fd1226181edb894f6c383 to your computer and use it in GitHub Desktop.
Save OKsign/ecae02815e8fd1226181edb894f6c383 to your computer and use it in GitHub Desktop.
# s28.1 - improved: getting current volume level
# This script is for volume level of sound output device >= 100%, but < 160%
# user options
notification = 'on' # 'on' or 'off'
# end of user options
#####################################################################################
info_sinks = system.exec_command("pacmd list-sinks | grep -Ei 'index:|active port:'")
all_lines = info_sinks.split("\n")
for line in all_lines:
if "active port:" in line:
target_index = all_lines.index(line)
string_of_line_index = all_lines[target_index - 1]
split_string = string_of_line_index.split(": ")
count_index = len(split_string)
num_index = split_string[count_index - 1]
time.sleep(0.05)
info_volume = system.exec_command("amixer get 'Master'")
all_lines_info_volume = info_volume.split("\n")
string_of_line_volume = all_lines_info_volume[4]
if "100%" in string_of_line_volume:
# info - volume 2
info_volume_2 = system.exec_command("pactl list sinks | grep Volume:")
all_lines_info_volume_2 = info_volume_2.split("\n")
string_of_line_volume_2 = all_lines_info_volume_2[0]
split_slash = string_of_line_volume_2.split("/")
index_1_split_slash = split_slash[1]
index_3_split_slash = split_slash[3]
split_percent = index_1_split_slash.split("%")
split_percent_index_3 = index_3_split_slash.split("%")
vo_index3 = split_percent_index_3[0]
vo = split_percent[0]
volume_level_index1 = float(vo)
volume_level_index3 = float(vo_index3)
if volume_level_index3 > volume_level_index1:
volume_level = volume_level_index3
else:
volume_level = volume_level_index1
if volume_level >= 100:
if volume_level < 103:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x10800" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 103%'")
quit()
else:
quit()
if volume_level >= 103:
if volume_level < 106:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x11000" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 106%'")
quit()
else:
quit()
if volume_level >= 106:
if volume_level < 109:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x11800" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 109%'")
quit()
else:
quit()
if volume_level >= 109:
if volume_level < 113:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x12000" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 112%'")
quit()
else:
quit()
if volume_level >= 113:
if volume_level < 116:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x12800" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 116%'")
quit()
else:
quit()
if volume_level >= 116:
if volume_level < 118:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x13000" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 119%'")
quit()
else:
quit()
if volume_level >= 118:
if volume_level < 122:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x13800" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 122%'")
quit()
else:
quit()
if volume_level >= 122:
if volume_level < 125:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x14000" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 125%'")
quit()
else:
quit()
if volume_level >= 125:
if volume_level < 128:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x14800" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 128%'")
quit()
else:
quit()
if volume_level >= 128:
if volume_level < 131:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x15000" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 131%'")
quit()
else:
quit()
if volume_level >= 131:
if volume_level < 134:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x15800" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 134%'")
quit()
else:
quit()
if volume_level >= 134:
if volume_level < 138:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x16000" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 138%'")
quit()
else:
quit()
if volume_level >= 138:
if volume_level < 141:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x16800" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 141%'")
quit()
else:
quit()
if volume_level >= 141:
if volume_level < 144:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x17000" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 144%'")
quit()
else:
quit()
if volume_level >= 144:
if volume_level < 147:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x17800" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 147%'")
quit()
else:
quit()
if volume_level >= 147:
if volume_level < 150:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x18000" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 150%'")
quit()
else:
quit()
if volume_level >= 150:
if volume_level < 153:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x18800" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 153%'")
quit()
else:
quit()
if volume_level >= 153:
if volume_level < 156:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x19000" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 156%'")
quit()
else:
quit()
if volume_level >= 156:
if volume_level < 160:
time.sleep(0.2)
system.exec_command("pacmd set-sink-volume %s 0x19900" % num_index)
if notification == 'on':
system.exec_command("notify-send 'Volume Level: 160%'")
if volume_level >= 160:
dialog.info_dialog("Volume Level >= 160%",
"This script is for volume level >= 100%, but less than 160%." , width = '450')
else:
dialog.info_dialog("Volume Level < 100%",
"This script is for volume level >= 100%, but less than 160%." , width = '450')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment