Class: Spty::Command::VolumeCommand
Constant Summary
collapse
- ASCRIPT_PLAYER_VOLUME_STATUS =
" tell application \"Spotify\" to return sound volume\n"
- ASCRIPT_PLAYER_VOLUME_UP =
" tell application \"Spotify\"\n set currentvol to get sound volume\n if currentvol > 90 then\n set sound volume to 100\n else\n set sound volume to currentvol + 10\n end if\n end tell\n"
- ASCRIPT_PLAYER_VOLUME_DOWN =
" tell application \"Spotify\"\n set currentvol to get sound volume\n if currentvol < 10 then\n set sound volume to 0\n else\n set sound volume to currentvol - 10\n end if\n end tell\n"
- ASCRIPT_PLAYER_VOLUME_SET =
" tell application \"Spotify\" to set sound volume to %<level>s\n"
Constants inherited
from BaseCommand
BaseCommand::ASCRIPT_PLAYER_DETECT
Class Method Summary
collapse
Methods inherited from BaseCommand
running?
Class Method Details
.call(options, _) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/spty/commands/volume_command.rb', line 3
def self.call(options, _)
return unless running?
action = options.shift
action = 'status' if action.nil?
if action =~ /\A\d+\z/
options = action.to_i
action = 'level'
end
begin
send(action.to_sym, options)
rescue NameError => _e
puts "unknown volume command #{action}"
end
end
|
.down(_options) ⇒ Object
57
58
59
60
|
# File 'lib/spty/commands/volume_command.rb', line 57
def self.down(_options)
Spty::AppleScriptRunner.call(ASCRIPT_PLAYER_VOLUME_DOWN)
status
end
|
.level(options) ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/spty/commands/volume_command.rb', line 65
def self.level(options)
if options < 0 || options > 100
puts 'volume level should be between 0 to 100'
return
end
script = format(ASCRIPT_PLAYER_VOLUME_SET, level: options)
Spty::AppleScriptRunner.call(script)
status
end
|
.status(_options = nil) ⇒ Object
27
28
29
30
|
# File 'lib/spty/commands/volume_command.rb', line 27
def self.status(_options = nil)
current_vol = Spty::AppleScriptRunner.call(ASCRIPT_PLAYER_VOLUME_STATUS)
puts "volume is at #{current_vol}"
end
|
.up(_options) ⇒ Object
42
43
44
45
|
# File 'lib/spty/commands/volume_command.rb', line 42
def self.up(_options)
Spty::AppleScriptRunner.call(ASCRIPT_PLAYER_VOLUME_UP)
status
end
|