You are not logged in.

#1 2013-07-11 00:00:13

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

statemgr - create state management scripts (post them here)

Introduction

I have caught myself basically rewriting the same script multiple times to manage some sort of state. For example, xrandr screen layouts for different locations, alsaequal states for different audio configurations, etc. It was time to generalize the functionality and pack it into a module.

I thus give you statemgr. To use it, all you need to do is define a name, a save function, and a load function. The module will then take care of the rest.


Example: fehbg-mgr

Here's a simple example for managing backgrounds with feh (provided in the fehbg-mgr package):

#!/usr/bin/bash

# identifying name
name_="fehbg"

# the first argument is the state file path
function save_state_()
{
  cp ~/.fehbg -- "$1"
}

# the first argument is the state file path
function load_state_()
{
  bash "$1"
}

source /usr/share/bash/statemgr

Help Message

$ fehbg help
fehbg-mgr - save and restore fehbg states

USAGE
  fehbg-mgr [statedir <path>] <save|load|delete> <state name>
  fehbg-mgr [purge|list|where|help]

  statedir <path>
    Select the state directory to use.

  save <state name>
    Save the current fehbg state.
    Previous saved states with the same name will be overwritten.

  load <state name>
    Load a saved fehbg state.
    Loading a state while an application is running may cause it to crash.

  delete <state name>
    Delete a saved fehbg state.

  purge
    Delete all saved states.
    This can be useful when switching equalizer plugins.

  list
    List the saved states.

  where
    Show the path to the current state directory.

  help
    Display this help message and exit.

This makes it very easy to switch between different backgrounds, such as when you want a darker background for transparent consoles or at night.

ObStateMgr

In addition to the module, the package also provides an Openbox pipe menu generator that will work with any script based on this module (very useful for managing screen layouts and desktop backgrounds, for example):
obstatemgr screenshot


Scripts

At the time of writing, the following scripts exist (in their own packages):

  • fehbg-mgr: desktop backgrounds with feh

  • xrandr-mgr: screenlayouts with xrandr/arandr

  • alsaequal-mgr: equalizer states (e.g. for headphones, stereo, laptop speakers)

For an up-do-date list of statemgr-based scripts, check the statemgr tag section of my project index page. I may create a generic package-generator script later and dump all of these scripts in a dir on my site (or just lump them together in a single package). If I dump them in a directory, you will also be able to get them with xacget.

Post any useful scripts that you create here and feel free to discuss the best way to distribute them. General feedback and suggestions for improvement are welcome as always.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB