-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarm.rb
executable file
·73 lines (60 loc) · 1.18 KB
/
alarm.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env ruby
module System
def self.os
@os ||= case RUBY_PLATFORM
when /linux/ then "Linux"
when /darwin/ then "Mac"
end
end
end
module Mixer
module Linux
def mute
system "amixer -c 0 -- sset Master 0%"
end
def mix from=50, to=100
from.upto(to) { |i| system "amixer -c 0 -- sset Master #{i}%"; sleep(1) }
end
end
module Mac
def mute
system "osascript -e 'set Volume 0'"
end
def mix
0.upto(10) { |i| system "osascript -e 'set Volume #{i}'"; sleep(15) }
end
end
def self.load_proper_os_module
self.const_get("#{System.os}")
end
include self.load_proper_os_module
end
module Player
module Linux
def play(song)
system "mpg123 '#{song}' &"
end
end
module Mac
def play(song)
system "/Applications/VLC.app/Contents/MacOS/VLC #{song} -Z &"
end
end
def self.load_proper_os_module
self.const_get("#{System.os}")
end
include self.load_proper_os_module
end
class Alarm
include Mixer
include Player
def initialize
mute
play(playlist)
mix
end
def playlist
@playlist = ARGV[0] || "playlist.m3u"
end
end
Alarm.new