def rename_workspaces(offset): for i, old_name in enumerate(workspace_names): new_name = i + offset + 1 res = i3.command('rename workspace {} to {}'.format( old_name, new_name)) if not res[0]['success']: err_fmt = '[{} - renumber] Rename failed: "{} to {}" on {}.\n' err_msg = err_fmt.format(time.strftime("%c"), old_name, new_name, workspace_names) err_msg += res[0]['error'] + '\n' log(err_msg) workspace_names[i] = new_name
from subprocess import Popen, PIPE import os import signal from fruity import prnt, log # Gets all open windows with their PIDs. wmctrl_lp = Popen(['wmctrl', '-lp'], stdout=PIPE, stderr=PIPE) out, err = [data.decode('utf-8') for data in wmctrl_lp.communicate()] out_lines = out.split('\n') window_pids = [] for line in out_lines: if line: # There are sometimes blank lines in wmctrl's output... window_pids.append(int(line.split()[2])) print("Window PIDs: {}".format(window_pids)) window_titles = [ "* " + line.split()[-1] + " (" + str(window) + ")" for line, window in zip(out_lines, window_pids) if line ] for pid in window_pids: os.kill(pid, signal.SIGTERM) window_kill_msg = "\n".join(window_titles) prnt("Killed all existing windows:\n{}".format(window_kill_msg)) log("Killed windows for cleaning:\n{}".format(window_kill_msg))
workspace_cmds = { 'workspace 1': [App('Terminal', 'xst')], 'workspace 2': [App('Browser', 'firefox')], 'workspace 3': [App('Email', 'thunderbird')], 'workspace 4': [App('Music', 'spotify')], } if socket.gethostname() == "graphite": workspace_cmds['workspace 5'] = [App('Slack', 'slack')] workspaces = sorted(workspace_cmds.keys()) previous_workspace = None for workspace in workspaces: apps = workspace_cmds[workspace] i3.command(workspace) for app in apps: base_msg = "{} with App: {}.".format(workspace.capitalize(), app.name) response = app.i3exec() if not response["success"]: prnt("Failed to set " + base_msg + ": " + response["error"]) i3.command(previous_workspace) continue prnt("Set " + base_msg) sleep(1) previous_workspace = workspace log("Workspaces initialized.")
def convert(convert_cmd): log("Final convert cmd: {}".format(convert_cmd)) conversion_proc = subprocess.Popen(convert_cmd) conversion_proc.wait()
# Extract CLI arguments. parser = argparse.ArgumentParser(description="Set the wallpaper on fruit.") parser.add_argument('image', type=str, help='The image to set as the new wallpaper.') parser.add_argument('fehmode', type=str, default='scale', nargs='?', help='The mode with which to set the wallpaper with feh.' + ' ({})'.format(",".join(FEH_OPTIONS))) args = parser.parse_args() if args.fehmode not in FEH_OPTIONS: log("Invalid fehmode given: {}".format(args.fehmode)) exit(0) def convert(convert_cmd): log("Final convert cmd: {}".format(convert_cmd)) conversion_proc = subprocess.Popen(convert_cmd) conversion_proc.wait() # Transfer over the wallpaper to ~/Pictures/wallpaper.[jpg|png]. final_lock_convert_cmd = ["convert", args.image, WALLPAPER_JPG_PATH] convert(final_lock_convert_cmd) # Fire the FEH command to update the bg. final_feh_cmd = FEH_CMD.format(args.fehmode).split()