Saturday, July 4, 2020

#1 2020-05-02 09:40:03 am

liuk0000
Member
Registered: 2019-02-12
Posts: 15

Control "Audio Devices" from terminal or applescript

HI all,

my Mac is having a sound issue that is only fixed when I
1) go to "/Utilities/Audio Midi Setup",
2) Select my audio device (it will be "External Headphones")
3) Change the sampling rate to (eg. if on 48,000 Hz, by putting it on 44,100 Hz).

I'm looking for a script, either from terminal or from AppleScript that is able to do that.

Is it possible?

Thanks!


Filed under: audio

Offline

 

#2 2020-05-02 12:42:54 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4533

Re: Control "Audio Devices" from terminal or applescript

You may enter the Preferences folder of your User Account, something like:
"SSD 1000:Users:**********:Library:Preferences:"
I guess that you will find a file named com.apple.xxxMidiyy.plist
Open it wit BBEdit and post the result here.
This way we would be able to give you a script able to edit this property list according to your requirements.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 2 mai 2020 20:42:48

Offline

 

#3 2020-05-02 02:49:39 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4533

Re: Control "Audio Devices" from terminal or applescript

If you can't edit the property list, you may use GUI Scripting.

Applescript:

(*

<key>EZZ-YH-uQs.ibShadowedLabels[0]</key>
   <string>Canaux</string> -- Channels
<key>EZZ-YH-uQs.ibShadowedLabels[1]</key>
   <string>Profondeur de bit</string> -- Bit Depth
<key>EZZ-YH-uQs.ibShadowedLabels[2]</key>
   <string>Format</string> -- Format
<key>EZZ-YH-uQs.ibShadowedLabels[3]</key>
   <string>Débit</string> -- Rate
<key>EbO-3B-WTi.label</key>
   <string>Sortie</string> -- Output
<key>M7l-iX-z2O.ibExternalAccessibilityDescription</key>
   <string>Horloge source</string> -- Clock Source
<key>nec-KC-gas.label</key>
   <string>Entrée</string> -- Input
<key>guw-kJ-yJv.title</key>
   <string>Source :</string> -- Source:
<key>gZJ-6C-MMO.title</key>
   <string>Format :</string> -- Format:
   
<key>Vva-Yz-dLj.ibExternalAccessibilityDescription</key>
   <string>Supprimer le périphérique agrégé</string> -- Remove Aggregate Device
<key>Y1g-eT-QpE.ibExternalAccessibilityDescription</key>
   <string>Créer un périphérique agrégé</string> -- Create Aggregate Device
<key>b2n-bJ-4Fu.title</key>
   <string>Périphériques audio</string> -- Audio Devices

   *)


property ruleHP : false -- Edit to fit your needs
-- true --> trigger UI ruling the HP
-- false --> doesn't triiger the UI ruling the HP

set theBundle to ((path to library folder from system domain as string) & "Extensions:AppleHDA.kext:") as «class furl»
set devShortNameOut_loc to localized string "DevShortNameOut" in bundle theBundle --> "Sortie intégrée"
set digitalOut_loc to localized string "DigitalOut" in bundle theBundle --> "Sortie numérique"
set devShortNameSpdo_loc to localized string "DevShortNameSpdo" in bundle theBundle --> "Sortie numérique intégrée"
set deviceNameDigitalOut_loc to localized string "DeviceNameDigitalOut" in bundle theBundle --> "Sortie numérique audio intégrée"
set deviceNameLineOut_loc to localized string "DeviceNameLineOut" in bundle theBundle --> "Sortie ligne audio intégrée"
set lineOut_loc to localized string "LineOut" in bundle theBundle --> "Sortie ligne"

set devShortNameHdpn_loc to localized string "DevShortNameHdpn" in bundle theBundle --> "Sortie - Écouteurs"
set deviceNameHeadphone_loc to localized string "DeviceNameHeadphone" in bundle theBundle --> "Sortie audio - Écouteurs"

set devShortNameLino_loc to localized string "DevShortNameLino" in bundle theBundle --> "Sortie ligne intégrée"

set sys2 to (system attribute "sys2") as integer
if sys2 > 13 then
   -- CAUTION, this string is used only since Mojave
   set theBundle to ((path to library folder from system domain as string) & "Audio:Plug-Ins:HAL:BridgeAudioSP.driver:") as «class furl»
   set headphones_loc to localized string "Headphones" in bundle theBundle --> "Écouteurs externes"
end if

if sys2 > 13 then
   set myOutPut to headphones_loc -- Edit to fit your needs
else
   set myOutPut to devShortNameLino_loc -- Edit to fit your needs by selecting one of the values defined above (maybe devShortNameHdpn_loc or deviceNameHeadphone_loc)
end if

set myRadioButton to 4 -- Edit to fit your needs -- Here I select "Débit"
-- 1 --> "Canaux"
-- 2 --> "Profondeur de bit"
-- 3 --> "Format"
-- 4 --> "Débit"

set myMenuItem to 7 -- Here I select "2 canaux 16 bits (44,1 kHz)" -- Edit to fit your needs

tell application "Audio MIDI Setup" to activate

tell application "System Events" to tell process "Audio MIDI Setup"
   set frontmost to true
   tell window 1
       -- class of UI elements --> {splitter group, button, button, button, static text}
       -- value of static text 1 --> "Périphériques audio"
       -- subrole of buttons --> {"AXCloseButton", "AXFullScreenButton", "AXMinimizeButton"}
       tell splitter group 1
           -- class of UI elements --> {button, menu button, button, menu button, scroll area, splitter, static text, static text, pop up button, button, tab}
           -- description of buttons --> {"bouton", "Supprimer le périphérique agrégé", "Aide"}
           -- description of menu buttons --> {"Créer un périphérique agrégé", "Action de l’appareil"}
           -- value of static texts --> {"Sortie intégrée", "Horloge source :"}
           tell scroll area 1
               -- class of UI elements --> {outline}
               tell outline 1
                   -- class of UI elements --> {row, row, row, row, column}
                   (*
   tell row 1
class of UI elements --> {UI element}
tell UI element 1
   class of UI elements --> {image, static text, static text, image, image, image}
   value of static texts --> {"Micro intégré", "2 entrées / 0 sortie"}
end tell
   end tell
   tell row 2
class of UI elements --> {UI element}
tell UI element 1
   class of UI elements --> {image, static text, static text, image, image, image}
   value of static texts --> {"Entrée intégrée", "2 entrées / 0 sortie"}
end tell
   end tell
   tell row 3
class of UI elements --> {UI element}
tell UI element 1
   class of UI elements --> {image, static text, static text, image, image, image}
   value of static texts --> {"Sortie intégrée", "0 entrée / 2 sorties"}
end tell
   end tell
   tell row 4
class of UI elements --> {UI element}
tell UI element 1
   class of UI elements --> {image, text field, static text, image, image, image, UI element}
   value of text field 1 --> "Pro Tools Aggregate I/O"
   value of static text 1 --> {"4 entrées / 2 sorties"}
   tell UI element 1
class of UI elements --> {}
   end tell
end tell
   end tell
*)

                   repeat with aRow in every row
                       if value of static text 1 of UI element 1 of aRow is myOutPut then
                           set {{x, y}, {w, h}} to {position, size} of aRow
                           tell me to do shell script "/usr/local/bin/cliclick c:" & x + w - 10 & "," & y + h div 2
                       end if
                   end repeat
                   
               end tell
           end tell
           tell splitter 1
               --class of UI elements --> {}
           end tell
           tell tab group 1
               -- class of UI elements --> {radio button, radio button, static text, pop up button, static text, pop up button, button, scroll area}
               -- value of static texts --> {"Source :", "Format :"}
               -- name of radio buttons --> {"Entrée", "Sortie"}
               -- description of pop up buttons --> {"Horloge source", "Format"}
               tell pop up button 1
                   -- its value --> "Haut-parleurs internes"
                   click it
                   tell menu 1 to get name of menu items --> {"Haut-parleurs internes"}
               end tell
               
               tell pop up button 2
                   -- its value --> "2 canaux 24 bits entier 44,1 kHz"
                   set {{x, y}, {w, h}} to {position, size}
                   tell me to do shell script "/usr/local/bin/cliclick dc:" & x + w - 10 & "," & y + h div 2
                   -- class of UI elements --> {menu}
                   tell menu 1
                       class of UI elements --> {menu item, menu item, menu item, menu item…
                       -- repeat with myRadioButton from 1 to 4 -- the count of possible radio buttons
                       tell menu item 1
                           -- its title --> missing value
                           click it
                           -- class of UI elements --> {radio group}
                           tell radio group 1
                               -- class of UI elements --> --> {radio button, radio button, radio button, radio button}
                               name of radio buttons --> {"Canaux", "Profondeur de bit", "Format", "Débit"}
                               tell radio button myRadioButton to click it
                           end tell -- radio group 1
                       end tell -- menu item 1
                       -- class of UI elements --> {menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item}
                       name of menu items
                       -- if myRadioButton = 1
                       --> {missing value, missing value, "2 canaux", "16 bit entier (44,1 kHz)", "16 bit entier (48,0 kHz)", "16 bit entier (88,2 kHz)", "16 bit entier (96,0 kHz)", "20 bit entier (44,1 kHz)", "20 bit entier (48,0 kHz)", "20 bit entier (88,2 kHz)", "20 bit entier (96,0 kHz)", "24 bit entier (44,1 kHz)", "24 bit entier (48,0 kHz)", "24 bit entier (88,2 kHz)", "24 bit entier (96,0 kHz)", "32 bit nombre à virgule flottante (44,1 kHz)", "32 bit nombre à virgule flottante (48,0 kHz)", "32 bit nombre à virgule flottante (88,2 kHz)", "32 bit nombre à virgule flottante (96,0 kHz)"}
                       
                       -- if myRadioButton = 2
                       --> {missing value, missing value, "16 bit", "2 canaux entier (44,1 kHz)", "2 canaux entier (48,0 kHz)", "2 canaux entier (88,2 kHz)", "2 canaux entier (96,0 kHz)", "20 bit", "2 canaux entier (44,1 kHz)", "2 canaux entier (48,0 kHz)", "2 canaux entier (88,2 kHz)", "2 canaux entier (96,0 kHz)", "24 bit", "2 canaux entier (44,1 kHz)", "2 canaux entier (48,0 kHz)", "2 canaux entier (88,2 kHz)", "2 canaux entier (96,0 kHz)", "32 bit", "2 canaux nombre à virgule flottante (44,1 kHz)", "2 canaux nombre à virgule flottante (48,0 kHz)", "2 canaux nombre à virgule flottante (88,2 kHz)", "2 canaux nombre à virgule flottante (96,0 kHz)"}
                       -- if myRadioButton = 3
                       --> {missing value, missing value, "Entier", "2 canaux 16 bits (44,1 kHz)", "2 canaux 16 bits (48,0 kHz)", "2 canaux 16 bits (88,2 kHz)", "2 canaux 16 bits (96,0 kHz)", "2 canaux 20 bits (44,1 kHz)", "2 canaux 20 bits (48,0 kHz)", "2 canaux 20 bits (88,2 kHz)", "2 canaux 20 bits (96,0 kHz)", "2 canaux 24 bits (44,1 kHz)", "2 canaux 24 bits (48,0 kHz)", "2 canaux 24 bits (88,2 kHz)", "2 canaux 24 bits (96,0 kHz)", "Nombre à virgule flottante", "2 canaux 32 bits (44,1 kHz)", "2 canaux 32 bits (48,0 kHz)", "2 canaux 32 bits (88,2 kHz)", "2 canaux 32 bits (96,0 kHz)"}
                       -- if myRadioButton = 4
                       (*{
missing value,
missing value,
"44,1 kHz",
"2 canaux 16 bits entier",
"2 canaux 20 bits entier",
"2 canaux 24 bits entier",
"2 canaux 32 bits nombre à virgule flottante", <-- What you asked for (index 7)
"48,0 kHz",
"2 canaux 16 bits entier",
"2 canaux 20 bits entier",
"2 canaux 24 bits entier",
"2 canaux 32 bits nombre à virgule flottante", <-- What is selectyed on your screenshot (index 12)
"88,2 kHz",
"2 canaux 16 bits entier",
"2 canaux 20 bits entier",
"2 canaux 24 bits entier",
"2 canaux 32 bits nombre à virgule flottante",
"96,0 kHz",
"2 canaux 16 bits entier",
"2 canaux 20 bits entier",
"2 canaux 24 bits entier",
"2 canaux 32 bits nombre à virgule flottante"}
*)

                       -- Here I select "2 canaux 16 bits (44,1 kHz)"
                       click menu item 4 -- Edit to fit yor needs
                       -- end repeat
                   end tell -- menu 1
               end tell -- pop up button 2
           end tell -- tab group 1
       end tell --splitter group 1
       
       
       if ruleHP then
           tell splitter group 1
               tell tab group 1
                   name of button 1 --> "Configuration des haut-parleurs…"
                   tell scroll area 1
                       class of UI elements --> {outline}
                       tell outline 1
                           class of UI elements --> {row, row, row, row, column, column, column, column, group}
                           tell row 1
                               class of UI elements --> {UI element}
                               tell UI element 1
                                   class of UI elements --> {static text, UI element}
                                   value of static text 1 --> {"Flux principal"}
                                   {role, value} of UI element 2 --> {"AXDisclosureTriangle", 1}
                               end tell
                           end tell -- row 1
                           tell row 2
                               class of UI elements --> {UI element}
                               tell UI element 1
                                   class of UI elements --> {static text, slider}
                                   value of static text 1 --> {"Maître"}
                                   {role, value, maximum value} of slider 1 --> {"AXSlider", 0.0, 1.0}
                               end tell
                           end tell -- row 2
                           tell row 3
                               class of UI elements --> {UI element}
                               tell UI element 1
                                   class of UI elements --> {static text, slider}
                                   value of static text 1 --> "1"
                                   {role, value, maximum value} of slider 1 --> {"AXSlider", 0.496105879545, 1.0}
                               end tell
                           end tell -- row 3
                           tell row 4
                               class of UI elements --> {UI element}
                               tell UI element 1
                                   class of UI elements --> {static text, slider}
                                   value of static text 1 --> "2"
                                   {role, value, maximum value} of slider 1 --> {"AXSlider", 0.496105879545, 1.0}
                               end tell
                           end tell -- row 4
                       end tell -- outline 1
                   end tell -- scroll area 1
               end tell -- tab group 1
           end tell -- splitter group 1
       end if -- ruleHP
   end tell
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 2 mai 2020 22:49:33

Edited according to complementary infos given below

Last edited by Yvan Koenig (2020-05-03 06:34:44 am)

Offline

 

#4 2020-05-03 04:09:52 am

liuk0000
Member
Registered: 2019-02-12
Posts: 15

Re: Control "Audio Devices" from terminal or applescript

Thanks Yvan!
Here's the content of the .plist file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>MIDISetup</key>
    <dict>
        <key>devices</key>
        <array>
            <dict>
                <key>apple.midirtp.errors</key>
                <data>
                </data>
                <key>driver</key>
                <string>com.apple.AppleMIDIRTPDriver</string>
                <key>entities</key>
                <array/>
                <key>image</key>
                <string>/System/Library/Extensions/AppleMIDIRTPDriver.plugin/Contents/Resources/RTPDriverIcon.tiff</string>
                <key>manufacturer</key>
                <string></string>
                <key>model</key>
                <string></string>
                <key>name</key>
                <string>Network</string>
                <key>offline</key>
                <integer>0</integer>
                <key>scheduleAheadMuSec</key>
                <integer>50000</integer>
                <key>uniqueID</key>
                <integer>2107508002</integer>
            </dict>
            <dict>
                <key>driver</key>
                <string>com.apple.AppleMIDIIACDriver</string>
                <key>entities</key>
                <array>
                    <dict>
                        <key>destinations</key>
                        <array>
                            <dict>
                                <key>uniqueID</key>
                                <integer>328332393</integer>
                            </dict>
                        </array>
                        <key>embedded</key>
                        <integer>1</integer>
                        <key>maxSysExSpeed</key>
                        <integer>3125</integer>
                        <key>name</key>
                        <string>Bus 1</string>
                        <key>sources</key>
                        <array>
                            <dict>
                                <key>uniqueID</key>
                                <integer>-813457346</integer>
                            </dict>
                        </array>
                        <key>uniqueID</key>
                        <integer>-355236570</integer>
                    </dict>
                </array>
                <key>image</key>
                <string>/System/Library/Extensions/AppleMIDIIACDriver.plugin/Contents/Resources/IACDriverIcon.tiff</string>
                <key>manufacturer</key>
                <string>Apple Inc.</string>
                <key>model</key>
                <string>IAC Driver</string>
                <key>name</key>
                <string>IAC Driver</string>
                <key>offline</key>
                <integer>1</integer>
                <key>uniqueID</key>
                <integer>-1783283715</integer>
            </dict>
            <dict>
                <key>Bluetooth Advertising Name</key>
                <string>YOOUMA-000</string>
                <key>driver</key>
                <string>com.apple.AppleMIDIBluetoothDriver</string>
                <key>entities</key>
                <array/>
                <key>image</key>
                <string>/System/Library/Extensions/AppleMIDIBluetoothDriver.plugin/Contents/Resources/BluetoothDeviceSetupIcon.tif</string>
                <key>is BLE MIDI null device</key>
                <integer>1</integer>
                <key>manufacturer</key>
                <string>Apple Inc.</string>
                <key>model</key>
                <string>Bluetooth MIDI Driver</string>
                <key>name</key>
                <string>Bluetooth</string>
                <key>offline</key>
                <integer>1</integer>
                <key>uniqueID</key>
                <integer>-58541406</integer>
            </dict>
        </array>
    </dict>
</dict>
</plist>

Offline

 

#5 2020-05-03 04:21:41 am

liuk0000
Member
Registered: 2019-02-12
Posts: 15

Re: Control "Audio Devices" from terminal or applescript

https://imgur.com/9QtBndo

image as a reference of my GUI

Offline

 

#6 2020-05-03 06:21:50 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: Control "Audio Devices" from terminal or applescript

Here is GUI scripting, as it works on the Catalina:

Applescript:


tell application "Audio MIDI Setup" to activate
tell application "System Events" to tell process "Audio MIDI Setup"
   repeat until window "Audio Devices" exists
       delay 0.02
   end repeat
   tell window "Audio Devices" to tell splitter group 1 to tell scroll area 1 to tell outline 1
       repeat with i from 1 to count rows
           if name of (static text 1 of UI element 1 of row i) is "External Headphones" then
               tell (static text 1 of UI element 1 of row i) to set {x, y} to position
               exit repeat
           end if
       end repeat
   end tell
   try
       tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y
   on error
       display dialog "Device \"External Headphones\" not found"
       return
   end try
   tell window "Audio Devices" to tell splitter group 1 to tell tab group 1
       tell (1st pop up button whose description is "Format")
           click it
           click radio button "Format" of radio group 1 of menu item 1 of menu 1
           click menu item "2 ch 24-bit (48,0 kHz)" of menu 1
       end tell
   end tell
end tell

Last edited by KniazidisR (2020-05-03 06:29:29 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#7 2020-05-03 06:38:54 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4533

Re: Control "Audio Devices" from terminal or applescript

liuk0000 wrote:

https://imgur.com/9QtBndo

image as a reference of my GUI




Thanks.

According to these infos I was able to edit the script.

(1) The used output isn't available in High Sierra so I introduced a test upon the running OS.
(2) According to your screenshot, it's the menu item at index 12 which is currently selected and you need to select the one whose index is 7.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 3 mai 2020 14:38:43

Offline

 

#8 2020-05-03 08:28:10 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4533

Re: Control "Audio Devices" from terminal or applescript

@KniazidisR

I assume that what you posted work on your machine but I'm sure that it doesn't on several others.

As always you forgot users which don't use English  but you forgot also that, for most of users using English, the decimal separator is not the comma but the period (dot).

I can't test but I guess that this version behaves better:

Applescript:

-- CAUTION, these strings are available in every languages only since Mojave
tell application "Audio MIDI Setup"
   set format_loc to localized string "EZZ-YH-uQs.ibShadowedLabels[2]" from table "AudioDevicePanel"
   set audioDevices_loc to localized string "F6X-ei-pg3.title" from table "NewAudioPanel"
   set menuItem_loc to localized string "%@ %u-bit (%.1f kHz)"
end tell

set sys2 to (system attribute "sys2") as integer
if sys2 > 13 then
   -- CAUTION, this string is used only since Mojave
   set theBundle to ((path to library folder from system domain as string) & "Audio:Plug-Ins:HAL:BridgeAudioSP.driver:") as «class furl»
   set headphones_loc to localized string "Headphones" in bundle theBundle --> "Écouteurs externes"
end if

set deci_loc to text 2 of ((0.5) as string)
set menuItem_loc to my remplace(menuItem_loc, "%@", "2 ch")
set menuItem_loc to my remplace(menuItem_loc, "%u", "24")
if deci_loc = "." then
   set menuItem_loc to my remplace(menuItem_loc, "%.1f", "48.0")"2 ch 24 bits (48.0 kHz)"
else
   set menuItem_loc to my remplace(menuItem_loc, "%.1f", "48,0") --> "2 ch 24 bits (48,0 kHz)"
end if

tell application "Audio MIDI Setup" to activate
tell application "System Events" to tell process "Audio MIDI Setup"
   repeat until window audioDevices_loc exists
       delay 0.02
   end repeat
   tell window audioDevices_loc to tell splitter group 1 to tell scroll area 1 to tell outline 1
       repeat with i from 1 to count rows
           if name of (static text 1 of UI element 1 of row i) is headphones_loc then
               tell (static text 1 of UI element 1 of row i) to set {x, y} to position
               exit repeat
           end if
       end repeat
   end tell
   try
       tell me to do shell script "/usr/local/bin/cliclick c:" & x & "," & y
   on error
       display dialog "Device “External Headphones” not found"
       return
   end try
   tell window "Audio Devices" to tell splitter group 1 to tell tab group 1
       tell (1st pop up button whose description is "Format")
           click it
           click radio button "format_loc" of radio group 1 of menu item 1 of menu 1
           click menu item menuItem_loc of menu 1
       end tell
   end tell
end tell


#=====
(*
replaces every occurences of d1 by d2 in the text t
*)

on remplace(t, d1, d2)
   local oTIDs, l
   set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
   set l to text items of t
   set AppleScript's text item delimiters to d2
   set t to l as text
   set AppleScript's text item delimiters to oTIDs
   return t
end remplace

#=====

On French systems, bit IS given a plural s and most of the time the decimal separator is the comma.
On English systems, bit IS NOT given a plural s and most of the time the decimal separator is the period.
On systems running zh_HK, bit is spelled 位元
There are also other changes like space character inserted here and there.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 3 mai 2020 16:25:26

Last edited by Yvan Koenig (2020-05-03 08:29:33 am)

Offline

 

#9 2020-05-06 07:24:00 am

liuk0000
Member
Registered: 2019-02-12
Posts: 15

Re: Control "Audio Devices" from terminal or applescript

Thanks a lot guys for your help. I was able to use your suggestions and integrate them with something more manageable to me, since I'll also have to maintain it and your code looks delicious, but I cannot really comprehend everything! My bad, I know... So, here's my working effort. Let me know what you think about it

Applescript:

tell application "Audio MIDI Setup" to activate
tell application "System Events"
tell application process "Audio MIDI Setup"
if not (window "Audio Devices" exists) then
click menu item "Show Audio Devices" of menu "Window" of menu bar item "Window" of menu bar 1
end if
select row 1 of outline 1 of scroll area 1 of splitter group 1 of window "Audio Devices"
tell window "Audio Devices" to tell splitter group 1 to tell tab group 1
tell (1st pop up button whose description is "Format")
click it
delay 0.2
click menu item 2 of menu 1
delay 1
click it
click menu item 1 of menu 1
end tell
end tell
end tell

end tell
tell application "Audio MIDI Setup" to quit

Last edited by liuk0000 (2020-05-06 07:24:50 am)

Offline

 

#10 2020-05-06 08:37:17 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4533

Re: Control "Audio Devices" from terminal or applescript

In my proposal, some instructions were grabbing the localized name of some UI elements.


When the system is running using a foreign language,
what is spelled "Audio Devices" on your machine is spelled "Périphériques audio" in French
what is spelled "2 ch 24-bit (48.0 kHz)" on your machine is spelled "2 ch 24 bits (48,0 kHz)" in French
what is spelled "External Headphones" on your machine is spelled "Écouteurs externes" in French

and the app may use 40 different languages.

As I am curious I wish to know what are the names of the menu items triggered by :

Applescript:

click menu item 2 of menu 1
delay 1
click it
click menu item 1 of menu 1

knowing that happily the description of their menu is spelled "Format" in French as it is in English (but spelled differently in several countries)

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 6 mai 2020 16:35:38

Offline

 

#11 2020-05-06 09:40:59 am

liuk0000
Member
Registered: 2019-02-12
Posts: 15

Re: Control "Audio Devices" from terminal or applescript

As I am curious I wish to know what are the names of the menu items triggered by :
Open this Scriplet in your Editor:
click menu item 2 of menu 1
delay 1
click it
click menu item 1 of menu 1



they are namely the first voice of the menu "44,100 Hz" and the second one "48,000 Hz".
By referring them as abstract ordered items, rather than using real string I guess it's safer since I bypass the language barriers! Numbers vs Language ;-)

Offline

 

#12 2020-05-06 10:09:16 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4533

Re: Control "Audio Devices" from terminal or applescript

To be complete, here are the spellings for External Microphone

ar    ميكروفون خارجي
ca    Micròfon extern
cs    Externí mikrofon
da    Ekstern mikrofon
de    Externes Mikrofon
el    Εξωτερικό μικρόφωνο
en_AU    External Microphone
en_GB    External Microphone
en    External Microphone
es_419    Micrófono externo
es    Micrófono externo
fi    Ulkoinen mikrofoni
fr_CA    Microphone externe
fr    Microphone externe
he    מיקרופון חיצוני
hi    बाहरी माइक्रोफ़ोन
hr    Vanjski mikrofon
hu    Külső mikrofon
id    Mikrofon Eksternal
it    Microfono Esterno
ja    外部マイク
ko    외장 마이크
ms    Mikrofon Luaran
nl    Externe microfoon
no    Ekstern mikrofon
pl    Mikrofon zewnętrzny
pt_PT    Microfone externo
pt    Microfone Externo
ro    Microfon extern
ru    Внешний микрофон
sk    Externý mikrofón
sv    Extern mikrofon
th    ไมโครโฟนภายนอก
tr    Harici Mikrofon
uk    Зовнішній мікрофон
vi    Micrô Ngoài
zh_CN    外置麦克风
zh_HK    外置咪高風
zh_TW    外接麥克風

here are the spellings for Format
ar    التنسيق
ca    Format
cs    Formát
da    Format
de    Format
el    Μορφή
en_AU    Format
en_GB    Format
en    Format
es_419    Formato
es    Formato
fi    Muoto
fr_CA    Format
fr    Format
he    תבנית
hi    फ़ॉर्मैट
hr    Format
hu    Formátum
id    Format
it    Formato
ja    フォーマット
ko    포맷
ms    Format
nl    Structuur
no    Format
pl    Format
pt_PT    Formato
pt    Formato
ro    Format
ru    Формат
sk    Formát
sv    Format
th    รูปแบบ
tr    Biçim
uk    Формат
vi    Định dạng
zh_CN    格式
zh_HK    格式
zh_TW    格式
   
here are the spellings for Audio Devices   
ar    أجهزة الصوت
ca    Dispositius d’àudio
cs    Zvuková zařízení
da    Lydenheder
de    Audiogeräte
el    Συσκευές ήχου
en_AU    Audio Devices
en_GB    Audio Devices
en    Audio Devices
es_419    Dispositivos de audio
es    Dispositivos de audio
fi    Äänilaitteet
fr_CA    Appareils audio
fr    Périphériques audio
he    התקני שמע
hi    ऑडियो डिवाइस
hr    Audio uređaji
hu    Audioeszközök
id    Perangkat Audio
it    Dispositivi audio
ja    オーディオ装置
ko    오디오 기기
ms    Peranti Audio
nl    Audioapparaten
no    Lydenheter
pl    Urządzenia audio
pt_PT    Dispositivos de áudio
pt    Dispositivos de Áudio
ro    Dispozitive audio
ru    Аудиоустройства
sk    Audiozariadenia
sv    Ljudenheter
th    อุปกรณ์เสียง
tr    Ses Aygıtları
uk    Аудіопристрої
vi    Thiết bị Âm thanh
zh_CN    音频设备
zh_HK    音訊裝置
zh_TW    音訊裝置
   
I hope that now the usefulness of instructions grabbing the localized names of UI elements is clear.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 6 mai 2020 18:09:02

Offline

 

#13 2020-05-06 12:56:06 pm

liuk0000
Member
Registered: 2019-02-12
Posts: 15

Re: Control "Audio Devices" from terminal or applescript

yes, quite challenging!
But thanks Yvan for your support, and thanks KniazidisR!
You helped me a lot!

Offline

 

#14 2020-05-06 01:24:05 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4533

Re: Control "Audio Devices" from terminal or applescript

liuk0000 wrote:

As I am curious I wish to know what are the names of the menu items triggered by :
Open this Scriplet in your Editor:
click menu item 2 of menu 1
delay 1
click it
click menu item 1 of menu 1



they are namely the first voice of the menu "44,100 Hz" and the second one "48,000 Hz".
By referring them as abstract ordered items, rather than using real string I guess it's safer since I bypass the language barriers! Numbers vs Language ;-)



Thanks.
These infos prove that the GUI is not built the same as in the version available under 10.13.

Here are the localized string used to build them

ar    %.0f هرتز
ca    %.0f Hz
cs    %.0f Hz
da    %.0f Hz
de    %.0f Hz
el    %.0f Hz
en_AU    %.0f Hz
en_GB    %.0f Hz
en    %.0f Hz
es_419    %.0f Hz
es    %.0f Hz
fi    %.0f Hz
fr_CA    %.0f Hz
fr    %.0f Hz
he    %.0f הרץ
hi    %.0f Hz
hr    %.0f Hz
hu    %.0f Hz
id    %.0f Hz
it    %.0f Hz
ja    %.0f Hz
ko    %.0fHz
ms    %.0f Hz
nl    %.0f Hz
no    %.0f Hz
pl    %.0f Hz
pt_PT    %.0f Hz
pt    %.0f Hz
ro    %.0f Hz
ru    %.0f Гц
sk    %.0f Hz
sv    %.0f Hz
th    %.0f Hz
tr    %.0f Hz
uk    %.0f Гц
vi    %.0f Hz
zh_CN    %.0f Hz
zh_HK    %.0f Hz
zh_TW    %.0f Hz

The final strings are built by replacing "%.0f" by the numerical the string representing the number of Hz using the local separator of thousands. Your "48,000" would be "48 000" on a system speaking French and applying the local rules of numbers formatting.
It's this kinds of features which push me to be demanding about published GUIScripting codes.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 6 mai 2020 21:24:01

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)