Skip to content

Commit

Permalink
os x muter, baby
Browse files Browse the repository at this point in the history
  • Loading branch information
rdp committed May 20, 2014
1 parent 9548c0d commit 8e39f74
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
27 changes: 25 additions & 2 deletions lib/muter.rb
Expand Up @@ -18,8 +18,29 @@
require 'rubygems' # ugh
require 'ffi'
require 'sane'
require 'os'
require_relative 'jruby-swing-helpers/lib/simple_gui_creator/mouse_control'
require_relative 'jruby-swing-helpers/lib/simple_gui_creator/play_audio'

if OS.x?

module Muter
def mute!
system(%!osascript -e "set volume with output muted"!)
end
def unmute!
system(%!osascript -e "set volume without output muted"!)
end
def hit_volume_up_key
system(%!osascript -e "set volume output volume (output volume of (get volume settings) + 5) --100%"!)
end
def hit_volume_down_key
system(%!osascript -e "set volume output volume (output volume of (get volume settings) - 5) --100%"!)
end
# allow for Muter.xxx
extend self
end

else

module Muter
# from msdn on keybd_event ...
Expand Down Expand Up @@ -63,7 +84,7 @@ def mute!
end
end

@@use_mouse_click = true
@@use_mouse_click = false # TODO if ever use this then...umm...fix it for mac too?

# LODO better for doze 7/xp
def unmute!
Expand All @@ -85,3 +106,5 @@ def unmute!
extend self

end

end
4 changes: 3 additions & 1 deletion spec/muter.spec.rb
Expand Up @@ -18,6 +18,8 @@
require File.dirname(__FILE__) + "/common"
require_relative '../lib/muter'

puts 'you manual test this one by playing something then watching it play or not'

describe 'manual muter' do
# functional test

Expand Down Expand Up @@ -47,4 +49,4 @@
p Benchmark.realtime { 1.times{Muter.unmute!}} # 0.00023848s
# seems actually like reasonable speed
Muter.unmute!
end
end

0 comments on commit 8e39f74

Please sign in to comment.