Class: Spty::Command::VolumeCommand
Constant Summary
collapse
- ASCRIPT_PLAYER_VOLUME_STATUS =
<<-EOL
tell application "Spotify" to return sound volume
EOL
- ASCRIPT_PLAYER_VOLUME_UP =
<<-EOL
tell application "Spotify"
set currentvol to get sound volume
if currentvol > 90 then
set sound volume to 100
else
set sound volume to currentvol + 10
end if
end tell
EOL
- ASCRIPT_PLAYER_VOLUME_DOWN =
<<-EOL
tell application "Spotify"
set currentvol to get sound volume
if currentvol < 10 then
set sound volume to 0
else
set sound volume to currentvol - 10
end if
end tell
EOL
- ASCRIPT_PLAYER_VOLUME_SET =
<<-EOL
tell application "Spotify" to set sound volume to %<level>s
EOL
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
|
.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