Hello,
I have been fooling around with JSA for MacOS and have written a sound output
changer program.
I am attaching the code below so that perhaps it might be of use.
Note, because of some code way down in the program the only output devices that
this program will switch to are "Jonathan's AirPods" and Internal speaker" you
can probably figure how to change these if you can get the code to compile.
Also note that VoiceOver AppleScript and allowing UI Scripting for the saved
application will probably be required. This appears to work in the last three
versions of MacOS. It does require that "Script Editor" is set to Javascript
and not AppleScript and I would recommend when saving that you save as an
application.
—code below —
"use script";
var app = Application( "System Preferences"),
preferencesActive = app.running(),
sound = app.panes[ "com.apple.preference.sound"],
sndOutputAnchor = sound.anchors.byName("output");
if (preferencesActive) {
var actPane = app.currentPane() ;
preferencesActive = actPane ? actPane : "True"
} ;
// Real the output paine of the sound pane of System Preferences.
app.activate();
sndOutputAnchor.reveal();
delay(.5); // wait half a sec to make sure pane is available.
var
appFrontWindow = Application("System
Events").applicationProcesses[app.name()].windows[0],
devices = appFrontWindow.tabGroups[0].scrollAreas[0].tables[0],
inactiveOutputs = devices.rows.whose({selected: "False"}),
c;
for(var i = 0, j = inactiveOutputs.length ; i < j ; i++) {
;
c =inactiveOutputs[i];
if ( c.uiElements[0].class() === 'textField') { // skip empty rows
var name, type ;
[name, value ] = c.uiElements.value();
// if (name.in(["Internal Speakers", "Jonathan’s AirPods"].) ) {
if ((name === "Jonathan’s AirPods" )
|| (name === "Internal Speakers"))
{
Application("VoiceOver").output( name + " will now be the output");
delay(.75);
c.select();
break;
} }
}
//Now somewhat restore System Preferences to former state.
if (! preferencesActive ) {
app.quit();
} else {
preferencesActive.reveal()
}
—-
Best wishes,
Jonathan Cohn
--
The following information is important for all members of the Mac Visionaries
list.
If you have any questions or concerns about the running of this list, or if you
feel that a member's post is inappropriate, please contact the owners or
moderators directly rather than posting on the list itself.
Your Mac Visionaries list moderator is Mark Taylor. You can reach mark at:
[email protected] and your owner is Cara Quinn - you
can reach Cara at [email protected]
The archives for this list can be searched at:
http://www.mail-archive.com/[email protected]/
---
You received this message because you are subscribed to the Google Groups
"MacVisionaries" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/macvisionaries.
For more options, visit https://groups.google.com/d/optout.