Skip to content

Instantly share code, notes, and snippets.

@robertmeta
Created August 26, 2011 09:45
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 robertmeta/1173083 to your computer and use it in GitHub Desktop.
Save robertmeta/1173083 to your computer and use it in GitHub Desktop.
Playing with Escript
#!/usr/bin/env escript
%%! -smp disable
-define(ENABLE, "1").
-define(DISABLE, "0").
main(Args) ->
try
case lists:flatten(string:to_lower(Args)) of
"enable" -> touchpad(enable);
"disable" -> touchpad(disable);
_ -> usage()
end
catch
_:_ -> usage()
end.
touchpad(enable) -> io:format("Enabling Touchpad\n"), touchpad(?ENABLE);
touchpad(disable) -> io:format("Disabling Touchpad\n"), touchpad(?DISABLE);
touchpad(StateChange) ->
Id = get_touchpad_id(get_input_devices()),
os:cmd("xinput set-prop "++Id++" \"Device Enabled\" "++StateChange).
get_touchpad_id(InputDevices) ->
{match, [[M]]} = re:run(InputDevices, "TouchPad.*id=(\\d+)", [global,{capture,[1],list}]),
M.
get_input_devices() -> os:cmd("xinput -list").
usage() -> io:format("~s [OPTIONS]\n\tenable\n\tdisable\n", [escript:script_name()]).
% vim: syntax=erlang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment