Last active
December 26, 2015 09:39
-
-
Save suna-pan/7130944 to your computer and use it in GitHub Desktop.
グラボへの給電を切り替える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
Plugin.create(:mikutter_bbswitch) do | |
filter_gui_postbox_post do |postbox| | |
buf = ObjectSpace.each_object(Gtk::PostBox).to_a.first.widget_post.buffer | |
if buf.text =~ /^bbswitch/ then | |
on if buf.text =~ /on$/ | |
off if buf.text =~ /off$/ | |
state if buf.text =~ /state$/ | |
buf.text = '' | |
Plugin.filter_cancel! | |
end | |
[postbox] | |
end | |
def announce(text) | |
Plugin.call(:update, nil, [Message.new(:message => text, :system => true)]) | |
end | |
def failed | |
announce('コマンドの実行に失敗しました。') | |
end | |
def state | |
begin | |
state = `cat /proc/acpi/bbswitch` | |
announce("現在の状態:#{state.strip}") | |
rescue | |
failed | |
end | |
end | |
def on | |
begin | |
`gksu "echo ON >/proc/acpi/bbswitch"` | |
state = `cat /proc/acpi/bbswitch` | |
if 'ON' == state.strip | |
announce('グラボに給電を開始しました。バッテリーの消費に注意してください。') | |
else | |
failed | |
end | |
rescue | |
failed | |
end | |
end | |
def off | |
begin | |
`gksu "echo OFF > /proc/acpi/bbswitch"` | |
state = `cat /proc/acpi/bbswitch` | |
if 'OFF' == state.strip | |
announce('グラボへの給電を停止しました。') | |
else | |
failed | |
end | |
rescue | |
failed | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment