Skip to content

Instantly share code, notes, and snippets.

@suna-pan
Last active December 26, 2015 09:39
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 suna-pan/7130944 to your computer and use it in GitHub Desktop.
Save suna-pan/7130944 to your computer and use it in GitHub Desktop.
グラボへの給電を切り替える
# -*- 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