Skip to content

Commit

Permalink
Support environment with no prior setting
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike committed May 1, 2024
1 parent 92e6fe1 commit 99387ba
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/install/macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,19 @@ async function enableExtension() {
*/
async function setSystemVoice(newValue) {
debug(`Setting macOS system voice to "${newValue}"`);
let stdout;

try {
({stdout} = await exec('defaults read com.apple.Accessibility SpeechVoiceIdentifierForLanguage'));
} catch (error) {
if (!error || !error.stderr.includes('does not exist')) {
throw error;
}
}

const {stdout} = await exec('defaults read com.apple.Accessibility SpeechVoiceIdentifierForLanguage');
const currentValue = stdout.replace(/[\s]/g, '').match(/2={en="([^"]+)";};/);
const currentValue = stdout ?
stdout.replace(/[\s]/g, '').match(/2={en="([^"]+)";};/) :
null;

debug(`Current value: ${currentValue ? JSON.stringify(currentValue[1]) : '(unset)'}`);

Expand Down

0 comments on commit 99387ba

Please sign in to comment.