I'm trying to create an Alfred workflow to change the volume with hotkeys through Alfred.
A working gem to control Sonos is here: https://github.com/soffes/sonos
The problem is: including the gem as part of a script just plain doesn't work. When I run the workflow nothing happens. I've attached a screenshot of the Alfred screenshot I'm talking about.
I've tried other Ruby scripts and they run just fine. But anything that requires a gem doesn't work.
I've also tried downloading the gem and just requiring the absolute path, but no luck there, either.
The sonos
gem uses the savon
gem for SOAP communication with the Sonos api. Savon
was logging to stdout
and that was preventing Alfred workflows from working (they depend on stdout
to communicate). My fork of the sonos gem disables the logging and can be used in your Alfred workflow.
require '/path/to/sonos'
Sonos.savon_config = { log: false }
speaker = Sonos::System.new.speakers.first
puts case "{query}"
when "play" then speaker.play and "Playing"
when "pause" then speaker.pause and "Paused"
when "up" then speaker.volume += 5 and "Turned up"
when "down" then speaker.volume -= 5 and "Turned down"
when "next" then speaker.next and "Next"
else "Unknown command"
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.