OliverJAsh Posted January 28, 2013 Posted January 28, 2013 I have an AirPlay device which I am constantly switching to and from, so I created this workflow that lets you quickly switch to the next available audio output device. http://cl.ly/3f3R383w002z Is there any way in which I can have the workflow show the current audio output device before you action the item, in this view: http://cl.ly/image/212K2H1R0e3C Florian 1
DavidK Posted January 28, 2013 Posted January 28, 2013 This is absolutely possible - You'll just need to use a Script Filter as your first item instead of Keyword, and then write a script to grab which is the active output and print the appropriate XML to display the info in the subtitle. See the following thread for details on passing feedback back to Alfred: http://www.alfredforum.com/index.php?/topic/5-generating-feedback-in-workflows/ Also, take a look at Mikegrb's Audio Device Selection workflow, which will likely do what you want already. http://mikegrb.com/2013/01/18/alfred2-audio-device/ Vero and OliverJAsh 2
OliverJAsh Posted January 29, 2013 Author Posted January 29, 2013 Here's what I came up with. Can you think of any way to improve it? http://cl.ly/1p1R0R1w0W1C I took inspiration from Mikegrb's workflow, but I only needed something that allowed me to toggle to the next device, rather than choose from a list. I wanted something quicker.
DavidK Posted January 29, 2013 Posted January 29, 2013 Seems to work well for me, nice job. My only suggestion would be to maybe list the "next device" in the subtitle output, so the user knows what it's going to switch to. Something like: "Current Device: Built-In Output, Next Device: Music Streamer II" OliverJAsh 1
OliverJAsh Posted January 30, 2013 Author Posted January 30, 2013 I had a go at doing that but my knowledge of Ruby is not good enough. The SwitchAudioSource CLI only gives you a list of available output devices, so I would need to compare that with the next output device to find the current output device. Unless you fancy having a go?
DavidK Posted January 30, 2013 Posted January 30, 2013 I don't know Ruby at all, but it shouldn't be too difficult. Looking at the documentation: "SwitchAudioSource -c" shows the current device "SwitchAudioSource -a" shows all devices Assuming the -n flag just chooses the next device in that list, you could easily just load the names generated by "-a" into an array. Then it's just a simple compare to find which array index matches the current device, say "n", and then print "n+1" as the next device. OliverJAsh 1
OliverJAsh Posted January 30, 2013 Author Posted January 30, 2013 -a outputs more along the lines of: Built-in Microphone (input) Built-in Output (output) AirPlay (output) Whereas -n outputs just: AirPlay … for example. I would need to trim the " (output)". If you could provide an example of how to do this, it would be appreciated. My knowledge of Ruby sucks (I never code in Ruby!). Edit: just seen you don't know Ruby either. I'll ask on IRC
DavidK Posted January 30, 2013 Posted January 30, 2013 I'm sure there's a more appropriate "Ruby" way of doing this with regular expressions, but here it is with sed: kair:Desktop dave$ ./SwitchAudioSource -a | grep "(output)" | sed 's/ (output)$//' Built-in Output Music Streamer II
OliverJAsh Posted January 30, 2013 Author Posted January 30, 2013 Great. Here's what I've put together, although I can't understand why it doesn't return anything: http://cl.ly/2b3P0s273m14 Thank you so much for your help thus far!
Florian Posted January 30, 2013 Posted January 30, 2013 I'd be interested in that workflow when it's done Keep up the good work !
DavidK Posted January 31, 2013 Posted January 31, 2013 I rewrote the functionality you are looking for using some bash trickery instead of Ruby. Seems to work fine in my setup, but feel free to test it out and let me know if there are any issues! http://d.pr/f/fB3c OliverJAsh and DJay 2
OliverJAsh Posted January 31, 2013 Author Posted January 31, 2013 That's perfect. Thank you very much!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now