def restore_volume(interprocess_dict): current_volume = interprocess_dict.get('current_volume', None) if current_volume is None: logging.debug('Current volume in dict is none') return current_volume_rounded = round(int(current_volume) / 10) cmd = get_set_volume_cmd_string(current_volume_rounded) exec_command(cmd, False, False) logging.debug(f'Restored current volume to {current_volume}') interprocess_dict['current_volume'] = None
def command_sound_post_snooze(interprocess_dict): # WARNING: Please increase the sleep timeout to a value larger than `SNOOZE_MINS`. # No sound will play if system is sleeping. # sudo pmset -a sleep 20 setproctitle.setproctitle(mp.current_process().name) wait_for_secs(SNOOZE_MINS * 60) store_current_volume(interprocess_dict) set_volume_to_max() for i in range(5): exec_command(cmd_sound_post_snooze) wait_for_secs(1) restore_volume(interprocess_dict)
def store_current_volume(interprocess_dict): res = exec_command("osascript -e 'get volume settings'", False) ret, stdout, stderr = res if ret == 0: current_volume = stdout.split(",")[0].split(":")[1].strip() interprocess_dict['current_volume'] = current_volume logging.debug(f'Stored current volume in dict = {current_volume}') else: logging.error(f'Error in retrieving current volume: {res}')
def set_volume_to_max(): cmd = get_set_volume_cmd_string(10) exec_command(cmd, False, False)
def command_make_sound(): setproctitle.setproctitle(mp.current_process().name) for interval in get_decreasing_seq(): # Start softly but go hard later. exec_command(cmd_sound) wait_for_secs(interval)