Skip to content

Instantly share code, notes, and snippets.

@micahbf
Created March 7, 2019 21:02
Show Gist options
  • Save micahbf/91a295016f4472b47acfe317d714350b to your computer and use it in GitHub Desktop.
Save micahbf/91a295016f4472b47acfe317d714350b to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# you must have SoX installed to generate touch tones
# brew install sox
# also, whatever application you run this script from will need to be authorized
# to control your computer, via System Preferences > Privacy > Accessibility
# finally, don't run this with headphones plugged in :)
### TONE GENERATION
FREQS = {
'1' => [697, 1209], '2' => [697, 1336], '3' => [697, 1477],
'4' => [770, 1209], '5' => [770, 1336], '6' => [770, 1477],
'7' => [852, 1209], '8' => [852, 1336], '9' => [852, 1477],
'*' => [941, 1209], '0' => [941, 1336], '#' => [941, 1477]
}
TONE_DURATION = 100
PAUSE_DURATION = 50
LONG_PAUSE_DURATION = 500
def push(key)
freq_x, freq_y = FREQS.fetch(key)
`/usr/local/bin/play -q -n synth #{TONE_DURATION.fdiv(1000)} sin #{freq_x} sin #{freq_y} remix -`
end
def pause
sleep PAUSE_DURATION.fdiv(1000)
end
def long_pause
sleep LONG_PAUSE_DURATION.fdiv(1000)
end
def dial(string)
string.each_char do |char|
if char =~ /[0-9#*]/
push(char)
pause
else
long_pause
end
end
end
### ZOOM SCRAPING
ZOOM_DIALOG_SCRIPT = <<-APPLESCRIPT
activate application "zoom.us"
tell application "System Events"
tell process "zoom.us" to get value of text area 1 of scroll area 1 of window "Choose ONE of the audio conference options"
end tell
APPLESCRIPT
dialog_contents = `osascript -e '#{ZOOM_DIALOG_SCRIPT}'`
meeting_id = dialog_contents.match(/Meeting ID:\s*([0-9 ]+)/)[1].gsub(/[^0-9]/, '')
participant_id = dialog_contents.match(/Participant ID:\s*([0-9 ]+)/)[1].gsub(/[^0-9]/, '')
### EMIT NOISES
current_volume = `osascript -e 'get output volume of (get volume settings)'`.chomp
`osascript -e 'set volume output volume 100'`
dial(meeting_id + '#')
sleep 1
dial(participant_id + '#')
`osascript -e "set volume output volume #{current_volume}"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment