Skip to content

Instantly share code, notes, and snippets.

@rtimpone
Created June 26, 2019 18:21
Show Gist options
  • Save rtimpone/bb93e2c852e72f783513eb16a5df40db to your computer and use it in GitHub Desktop.
Save rtimpone/bb93e2c852e72f783513eb16a5df40db to your computer and use it in GitHub Desktop.
Script to sync AirPods to a mac
-- Launch System Preferences
tell application "System Preferences" to activate
-- Open the 'Sound' preferences and select the 'Output' tab
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell application "System Events" to tell process "System Preferences"
set airpodsName to "RobÕs Airpods"
--need to make multiple attempts because the AirPods ususally take a few seconds to appear in the list
repeat 10 times
if exists row 1 of table 1 of scroll area 1 of tab group 1 of window 1 where value of text field 1 is airpodsName
tell table 1 of scroll area 1 of tab group 1 of window 1
select (row 1 where value of text field 1 is airpodsName)
end tell
delay 1
exit repeat
else
delay 1
end if
end repeat
end tell
-- Select the 'Input' tab of the Sound preferences
tell application "System Preferences"
reveal anchor "input" of pane id "com.apple.preference.sound"
end tell
-- Set the microphone to MacBook instead of AirPods to avoid audio quality issues
tell application "System Events" to tell process "System Preferences"
delay 1
tell table 1 of scroll area 1 of tab group 1 of window 1
select (row 0 where value of text field 1 is "MacBook Pro Microphone")
end tell
delay 1
end tell
tell application "System Preferences" to quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment