Class: Spty::Command::PauseCommand

Inherits:
BaseCommand show all
Defined in:
lib/spty/commands/pause_command.rb

Constant Summary collapse

ASCRIPT_PLAYER_PAUSE =
<<-EOL
  tell application "Spotify"
    pause
  end tell
EOL

Constants inherited from BaseCommand

BaseCommand::ASCRIPT_PLAYER_DETECT

Class Method Summary collapse

Methods inherited from BaseCommand

running?

Class Method Details

.call(options, _) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/spty/commands/pause_command.rb', line 8

def self.call(options, _)
  return unless running?

  # Get the player state
  player_state_script = Spty::Command::StateCommand::ASCRIPT_PLAYER_STATE
  player_state = Spty::AppleScriptRunner.(player_state_script)

  if player_state.strip == 'playing'
    Spty::AppleScriptRunner.call(ASCRIPT_PLAYER_PAUSE)
  end

  track_info_script = Spty::Command::InfoCommand::ASCRIPT_TRACK_INFO
  track_info = Spty::AppleScriptRunner.(track_info_script)

  puts "=> #{track_info.strip} [paused]"
end