Turn your iPhone into a cough button

[Tweet]

Mute icon

Update: These are the notes for the original version, which worked by sending the toggle command to MuteMyMic. Coughbutton has been revised to work with On/Off commands for Skype directly, no longer toggling system mute. This is more useful to me, and hopefully to others. The Github link is the same, and there’s a post with revised information.

I went down a deep rabbit hole on Saturday. It was painful because it should have been a 30-minute project, but I lost three hours of weekend. Maybe more, I lost track. I’m posting the solution so that at least one other person can help me divide up the time it will take to make the investment pay off.

I wanted a cough button for my USB microphone to avoid some editing when screencasting and podcasting. Michael Schechter has been down this road, too. Basically, I found that the mute button on my Yeti had the potential for bumping and creating click noises when used during recording. Michael’s solution of hooking up MuteMyMic was great, but using my Magic Trackpad with BetterTouchTool had its own issues. Namely, a swipe gesture wasn’t reliable enough. When you have to cough or sneeze, you don’t have time to position your hand correctly and ensure that the gesture is triggered. Same with tap gestures, but with the added problem of resonating noise if your mic is in any way connected to your desk.

I went looking for an external input solution. My rarely-used sustain pedal for my keyboard turned out to be broken, as did my old PowerMate. I have an extra Magic Trackpad around that I considered turning into a foot pedal, but that presented its own issues (mainly that I couldn’t click it reliably on carpet). I eventually turned to the last piece of hardware I had handy: my iPhone.

It didn’t take long to adapt my old HomeControl project to call an AppleScript that ran set volume input volume 0. 30 minutes, case closed. The problem turned out to be that the AppleScript command only looked like it was working. The slider went to zero, but the mic never cut off. A bit of searching indicated that this is a widespread issue on all Macs. The only solution is to switch the input to the built-in line input and have the volume on that set to 0 in preferences. There’s no way to do that via scripting, other than UI scripting with System Events. I refused to accept that.

I toyed with various Keyboard Maestro possibilities, and eventually broke down and wrote an AudioToolkit command line tool that would handle it. Then I went to trigger that from the PHP script running the remote and found that I couldn’t get it to execute within my user session, meaning that it worked, it just didn’t set the preference in any way that mattered to my logged in user. Bollocks. I watched a movie and went to bed.

In the morning I acquiesced to using MuteMyMic. I can trigger it from the PHP script with a simulated keypress and I modified my script to just send the same keystroke every time, toggling the visible state on the iPhone accordingly. And with that, I present Coughbutton. It has some requirements that might make it unsuitable for some people, but a little fiddling and you can have a perfectly silent remote for your microphone mute.

Purpose

CoughButton is a small PHP script and iPhone-friendly web app that does one simple thing: press opt-F5 on your Mac to toggle MuteMyMic.

CoughButton uses jQuery and the Hammer.js jQuery plugin to provide a tap-and-hold feature so that your iPhone functions like a real cough button. Press and hold the screen and your mic will be muted, when you let up it will unmute.

Installation

You need a local web server running PHP and a way to load it on your iPhone. This can be done by turning on the apache web server with PHP enabled and setting up a virtual host. If you don’t know how to do that, I recommend using MAMP.

Unzip the download into a folder in “Sites” in your home directory. Point your virtual host to it and you’re ready to go.

You’ll also need MuteMyMic installed and running.

Open your virtual host address/port in Mobile Safari on your iPhone. Use the send button at the bottom of the mobile Safari window to “Add to Homescreen.” Leave Safari and launch the new icon it creates.

Usage

Make sure that MuteMyMic is running and set to unmuted. Tap and hold your screen and you should see the MuteMyMic icon in your menu bar turn red, returning to black when you release.

To toggle, just tap lightly once. This will hard switch between muted and unmuted.

If something goes wrong and the sync between the iPhone screen color and the actual state of MuteMyMic gets off, you can double tap the screen to switch MuteMyMic without changing the state of CoughButton.

If you’re barefoot and don’t mind touching your iPhone with your feet, it makes a decent foot pedal, too.

Download

Coughbutton on Github. If you have git installed, I do recommend heading to the master repository and cloning the repo, just for the sake up easy updating as I make the tweaks that it needs.