Repository navigation
add audio-device extension - #144
Conversation
|
Is this link suppose to contain a video? It's just a still image for me (checked in multiple browsers) Also from quick look I noticed that your command names don't follow Title Case naming convention. Could you please take a look at our guidelines document: https://developers.raycast.com/basics/prepare-an-extension-for-store. |
|
Yeah, it has been a gif. Somehow one would need to hit Download for it do be played. I guess that's due to the file size. Anyway, I converted it into a video and updated the link. Also fixed the casing issue. |
pernielsentikaer
left a comment
There was a problem hiding this comment.
Awesome extension @benvp 💪
I'm not sure if the problem is occurring for me because I'm on Monterey, but I can't get it to set any other Audio Output Device than my Bluetooth headset (but that works well with the change from default speakers to Bluetooth)
QhSKu7kimfh0vOfo.mp4
The only error I see in the debug log is when changing to "Background Music" - the two other choices don't do anything.
Stack trace
Timestamp Ty Process[PID:TID]
2021-10-22 21:26:26.050 Db Raycast[11539:2381c6] [com.raycast.extensions.audio-device:set-output-device] Error: Command failed: /usr/local/Cellar/switchaudio-osx/1.1.0/SwitchAudioSource -t output -u (null)
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `/usr/local/Cellar/switchaudio-osx/1.1.0/SwitchAudioSource -t output -u (null)'
at ChildProcess.exithandler (node:child_process:397:12)
at ChildProcess.emit (node:events:390:28)
at maybeClose (node:internal/child_process:1064:16)
at Socket.<anonymous> (node:internal/child_process:450:11)
at Socket.emit (node:events:390:28)
at Pipe.<anonymous> (node:net:672:12) {
killed: false,
code: 2,
signal: null,
cmd: '/usr/local/Cellar/switchaudio-osx/1.1.0/SwitchAudioSource -t output -u (null)',
stdout: '',
stderr: "/bin/sh: -c: line 0: syntax error near unexpected token `('\134n" +
"/bin/sh: -c: line 0: `/usr/local/Cellar/switchaudio-osx/1.1.0/SwitchAudioSource -t output -u (null)'\134n"
}
pernielsentikaer
left a comment
There was a problem hiding this comment.
Found a few more corrections
| function SetAudioDeviceAction({ device }: SetAudioDeviceActionProps) { | ||
| return ( | ||
| <ActionPanel.Item | ||
| title="Make active" |
There was a problem hiding this comment.
| title="Make active" | |
| title="Select" |
Select is not necessary the one you have to choose, but it needs to follow the naming convention like "Set Active" "Make Active" "Select"
| "title": "Set Output Device", | ||
| "subtitle": "Audio Device", | ||
| "description": "Sets the active audio output device.", | ||
| "keywords": [ |
There was a problem hiding this comment.
| "keywords": [ |
Unnecessary keywords, It's already indexed by title and subtitle
| "subtitle": "Audio Device", | ||
| "description": "Sets the active audio output device.", | ||
| "keywords": [ | ||
| "audio", |
There was a problem hiding this comment.
| "audio", |
| "description": "Sets the active audio output device.", | ||
| "keywords": [ | ||
| "audio", | ||
| "device", |
| "keywords": [ | ||
| "audio", | ||
| "device", | ||
| "output" |
| "description": "Sets the active audio input device.", | ||
| "keywords": [ | ||
| "audio", | ||
| "device", |
| "keywords": [ | ||
| "audio", | ||
| "device", | ||
| "input" |
| "audio", | ||
| "device", | ||
| "input" | ||
| ], |
| "name": "switchAudioSourcePath", | ||
| "title": "SwitchAudioSource (switchaudio-osx) path", | ||
| "description": "Your local path to SwitchAudioSource.", | ||
| "link": "https://github.com/deweller/switchaudio-osx", |
There was a problem hiding this comment.
| "link": "https://github.com/deweller/switchaudio-osx", |
There is no link attribute
There was a problem hiding this comment.
This structure has basically been copied from the "Tower" extension. Will remove it.
| "link": "https://github.com/deweller/switchaudio-osx", | ||
| "type": "textfield", | ||
| "default": "/opt/homebrew/bin/SwitchAudioSource", | ||
| "value": "/opt/homebrew/bin/SwitchAudioSource", |
There was a problem hiding this comment.
| "value": "/opt/homebrew/bin/SwitchAudioSource", |
commented
Oct 24, 2021
|
@pernielsentikaer Do you mind running |
commented
Oct 24, 2021
|
Hi @benvp 👋 I added -a to the command, otherwise I just got an error, here is the output for you: |
commented
Oct 25, 2021
|
@pernielsentikaer Could you try that again? Seems like the |
left a comment
•
There was a problem hiding this comment.
That worked a lot better @benvp 💪 Confirming that changing from a Bluetooth headset and back to build-in speakers works as intended.
I tried to rewrite your useAudioDevices function since there is some empty state flicker going on rarely
export function useAudioDevices(type: "input" | "output") {
const [isLoading, setIsLoading] = useState(false);
const [audioDevices, setAudioDevices] = useState<UseAudioDevicesResponse["data"]>();
useEffect(() => {
const fetchDevices = async () => {
setIsLoading(true);
try {
const allDevicesResult = await execp(`${switchAudioPath()} -a -t ${type} -f json`);
const currentDeviceResult = await execp(`${switchAudioPath()} -c -t ${type} -f json`);
const devices = parseSwitchAudioOutput(allDevicesResult.stdout);
const current = parseSwitchAudioOutput(currentDeviceResult.stdout)[0];
setAudioDevices({
devices,
current,
});
} catch {
await showToast(ToastStyle.Failure, `Error!`, `There was an error fetching the audio devices.`);
} finally {
setIsLoading(false);
}
};
fetchDevices();
}, [type]);
return {
isLoading,
data: audioDevices,
};
}
I'll check if its caused by a known bug and get back to you
commented
Oct 26, 2021
|
@benvp, we'll need to hold on with merging this PR. We want to discuss internally what to do with extensions that require installation of some third party CLIs. My worry that for such simple use cases like this (changing output), it might be quite a bummer for users when they see that installation of some CLI is required. Some users might not even have Btw, in the meantime, if you find a way to use something like AppleScript for it, it could be a huge UX win. |
commented
Oct 27, 2021
|
@PitNikola I understand. AppleScript could somewhat work (by automating clicks to system preferences etc) but I don't think that it provides a nice UX as it could also break between macOS Releases and could be different throughout macOS versions. |
commented
Oct 29, 2021
|
As a user I would love to see this merged, I don't think it's too much to ask that certain dependencies be installed, as long as it's documented somewhere. Even the emoji extension downloads dependencies on startup. That being said, here is an example of applescript controlling the sound input: https://github.com/raycast/script-commands/blob/master/commands/system/audio/audio-output-switch.template.applescript I don't think there is a way to get the list of all available input sources through apple script though, that's the key and why this dependency is important. |
commented
Oct 29, 2021
|
@waynehoover you can at any time just import it yourself if you want have it |
commented
Nov 2, 2021
|
@benvp, we had an internal discussion about that and came to agreement that there must be a better way to handle dependencies like that. Do you think it would be possible to download a compiled version of the CLI if it's missing and then use it under the hood when running the extension? You have nodejs at your disposal for it. You should be able to identify the machine's architecture to download the correct CLI. What do you think? Our main goal with the extension store is to make it easy to install and run all these "little productivity apps". If we end up with a lot of extensions that ask you to install additional CLIs, it will significantly degrade experience of the Store and Raycast in general. I hope you can understand our intention. Thanks! |
commented
Nov 3, 2021
|
I'm not sure it does what you want out of the box, but could https://www.npmjs.com/package/macos-audio-devices solve it somehow? |
commented
Nov 10, 2021
|
@pernielsentikaer This looks promising. Quickly tested that package locally and seems to work fine. Let me see if I make the time to update the code to use this package in the next couple of days. |
commented
Nov 10, 2021
|
https://github.com/karaggeorge/macos-audio-devices will require Swift runtime libraries so it might be even more hassle than |
commented
Nov 10, 2021
|
@PitNikola But it's only when you have High Sierra or lower. From 10.14 Mojave (Released in 2018) it's build-in out of the box and then we support the last 4 versions. Raycast itself requires macOS 10.14+ so I think we're good to go as I read it? |
commented
Nov 10, 2021
|
Oh, ok, I misread the doc. If it works without any additional installations, then great 👍 |
commented
Nov 17, 2021
|
Hi @benvp 👋 Do you need any help regarding this, just checking if there is something you need help with 😄 |
left a comment
There was a problem hiding this comment.
Hi @benvp 🔥
Thanks for the update, it looks very nice with the subtitle 🚀 I have been a long journey, but it's worth the waiting time – what a lovely extension that we can ship 🚢
I'm going to accept it and then will my colleague do a final review before it's finally merged.
commented
Jan 14, 2022
|
Published to the Raycast Store: |
commented
Jan 14, 2022
|
@fe9lix I'm curious, what made you change your mind regarding the included binary vs a downloaded one? Thanks for merging, though. 🚀 |
Description
Adds a new extension for switching audio devices (input/output) via raycast using the macos-audio-devices utility.
Type of change
Screencast
https://capture.dropbox.com/E6pbSuaX61nhziEM
Checklist
512x512