Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Push To Talk - Google Meet Bookmarklet

Short link to this page: http://caseywatts.com/ptt

Other gists & tricks: http://caseywatts.com/gists-and-tricks

Unrelated update: my book is out! Debugging Your Brain is an applied psychology / self-help book

Push To Talk in a Google Hangout (Meet)

  1. Save this bookmarklet. Right-click on boomarks toolbar Add Page...
    • Name: PTT (push to talk) or whatever you'd like (maybe short so it stays on your bookmarks toolbar)
    • URL: (paste in the bookmarklet.js contents below)
  2. In a Meet, click on the bookmarklet
  3. Press and hold spacebar to talk. Keydown will un-mute you, and keyup will re-mute you.
  4. 🎉
javascript: (() => {
const toggle = tip => ({ key }) =>
key === ' ' && document.querySelectorAll('[data-tooltip]').forEach(el => el.dataset.tooltip === tip && el.click());
document.body.onkeyup = toggle('Turn off microphone');
document.body.onkeydown = toggle('Turn on microphone');
})(); // fixed by @sparksm
javascript:(function(){
document.body.onkeyup = function(e){
if(e.keyCode == 32){
document.querySelector('[data-tooltip="Turn off microphone"]').click(); // Meet
// document.querySelector('[data-tooltip="Mute microphone"]').click(); // Hangouts, but it doesn't work
}
};
document.body.onkeydown = function(e){
if(e.keyCode == 32){
document.querySelector('[data-tooltip="Turn on microphone"]').click(); // Meet
// document.querySelector('[data-tooltip="Unmute microphone"]').click(); // Hangouts, but it doesn't work
}
};
})();
@adunkman

This comment has been minimized.

Copy link

@adunkman adunkman commented Jun 2, 2017

Is $ defined in the page?

If you’re using Chrome, the developer tools define $ for you — https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference#queryselector — but it’s not present in the page.

If that’s the case, you should be able to replace it with:

document.querySelector('[data-tooltip~="microphone"]').click();
@caseywatts

This comment has been minimized.

Copy link
Owner Author

@caseywatts caseywatts commented Jun 2, 2017

@adunkman my hero! :D

@co0l3y

This comment has been minimized.

Copy link

@co0l3y co0l3y commented Nov 2, 2017

Does this work for anyone? Can't get it to work in google meet or hangouts.

@caseywatts

This comment has been minimized.

Copy link
Owner Author

@caseywatts caseywatts commented Nov 22, 2017

it stopped working for me at some point, and I haven't gotten it working again :/

I've been using this desktop one instead, which works across even more videochat apps (except for Zoom, unfortunately): https://github.com/yulrizka/osx-push-to-talk

@sparksm

This comment has been minimized.

Copy link

@sparksm sparksm commented Jul 11, 2018

javascript: (() => {
  const toggle = tip => ({ key }) =>
    key === ' ' && document.querySelectorAll('[data-tooltip]').forEach(el => el.dataset.tooltip === tip && el.click());
  document.body.onkeyup = toggle('Turn off microphone');
  document.body.onkeydown = toggle('Turn on microphone');
})();
@edabot

This comment has been minimized.

Copy link

@edabot edabot commented Dec 19, 2018

Thank you, @sparksm! Worked for me.

@deanmarano

This comment has been minimized.

Copy link

@deanmarano deanmarano commented Dec 26, 2018

👍 for @sparksm! works great :)

@mgohin

This comment has been minimized.

Copy link

@mgohin mgohin commented Mar 22, 2019

french version

javascript: (() => {
  const toggle = tip => ({ key }) =>
    key === ' ' && document.querySelectorAll('[data-tooltip]').forEach(el => el.dataset.tooltip === tip && el.click());
  document.body.onkeyup = toggle('Désactiver le micro');
  document.body.onkeydown = toggle('Activer le micro');
})();
@adriancampos

This comment has been minimized.

Copy link

@adriancampos adriancampos commented Jun 10, 2019

It seems that Hangouts removed tooltips (as far as I can tell). Using aria labels instead:

javascript: (() => {
  const toggle = tip => ({ key }) =>
    key === ' ' && document.querySelectorAll('[aria-label]').forEach(el => el.getAttribute('aria-label') === tip && el.click());
  document.body.onkeyup = toggle('Mute microphone');
  document.body.onkeydown = toggle('Unmute microphone');
})();
@rodricels

This comment has been minimized.

Copy link

@rodricels rodricels commented Sep 5, 2019

A international version for Google Meet:

javascript: (() => {
  const toggle = tip => ({ key }) =>
    key === ' ' && document.querySelector('[data-is-muted="false"] > div').click();
  document.body.onkeyup = toggle('False');
  document.body.onkeydown = toggle('True');
})(); 

The problem with these Push To Talk solutions is that the chat stops working :(

@davebeesley

This comment has been minimized.

Copy link

@davebeesley davebeesley commented Nov 26, 2019

Tried this on Mac, it keeps toggling rather than keydown unmute, keyup mute

@MrTrick

This comment has been minimized.

Copy link

@MrTrick MrTrick commented Jan 30, 2020

I've built an international solution that doesn't break any chat or other features. 🤞
https://github.com/MrTrick/greasemonkey-scripts/blob/master/Google%20Meet%20Hangouts%20-%20PTT.js
Hope it's helpful for someone.

@Dropheart

This comment has been minimized.

Copy link

@Dropheart Dropheart commented Mar 10, 2020

Thanks @MrTrick, going to have to use Google Meet for school related things and your script worked!

@callumacrae

This comment has been minimized.

Copy link

@callumacrae callumacrae commented Mar 18, 2020

I had to replace el.dataset.tooltip === tip with el.dataset.tooltip.includes(tip) to get this to work - it has the keyboard shortcut in the text as well

@harry-m

This comment has been minimized.

Copy link

@harry-m harry-m commented Mar 19, 2020

I had to add " (⌘ + d)" to the tooltips to make this work:

javascript: (() => {  const toggle = tip => ({ key }) =>    key === ' ' && document.querySelectorAll('[data-tooltip]').forEach(el => el.dataset.tooltip === tip && el.click());  
document.body.onkeyup = toggle('Turn off microphone (⌘ + d)');  
document.body.onkeydown = toggle('Turn on microphone (⌘ + d)');})(); // fixed by @sparksm
@jdecew

This comment has been minimized.

Copy link

@jdecew jdecew commented Mar 20, 2020

Same as above, but for linux:

javascript: (() => {  const toggle = tip => ({ key }) =>    key === ' ' && document.querySelectorAll('[data-tooltip]').forEach(el => el.dataset.tooltip === tip && el.click());  
document.body.onkeyup = toggle('Turn off microphone (ctrl + d)');  
document.body.onkeydown = toggle('Turn on microphone (ctrl + d)');
})();
@callumacrae

This comment has been minimized.

Copy link

@callumacrae callumacrae commented Mar 20, 2020

javascript: (() => {
  const toggle = tip => ({ key }) =>
    key === ' ' && document.querySelectorAll('[data-tooltip]').forEach(el => el.dataset.tooltip.includes(tip) && el.click());
  document.body.onkeyup = toggle('Turn off microphone');
  document.body.onkeydown = toggle('Turn on microphone');
})(); // fixed by @sparksm 

.includes means this works for all OSs :)

@preston-hf

This comment has been minimized.

Copy link

@preston-hf preston-hf commented Mar 25, 2020

Is there any way that you could do this globally? It would be awesome to have PTT when the window isn't focused.

@discentem

This comment has been minimized.

Copy link

@discentem discentem commented Mar 26, 2020

Is there any way that you could do this globally? It would be awesome to have PTT when the window isn't focused.

+1

@RanieriC

This comment has been minimized.

Copy link

@RanieriC RanieriC commented Mar 27, 2020

Is there any way that you could do this globally? It would be awesome to have PTT when the window isn't focused.

You could probably setup a lua macro script and set that SPACE executes SPACE in the specific tab.
However, I suspect that might cause for the Google Meet chat and other stuff in Chrome to stop working
If you're interested in doing it, I can help you. DM me on Discord: Ranieri#1 or email me at ranieri.campello06@gmail.com
Kind Regards!

@bitmvr

This comment has been minimized.

Copy link

@bitmvr bitmvr commented Apr 6, 2020

I was originally using the solution mentioned above. But as quarantine has become the norm for the most of us, I was determined to come up with a more global solution so I can unmute/mute despite what application context I have (a.k.a. A global 'soft' kill switch)

The directions and 'code' are available in this article I created ...

How In The Bleep Do I Mute My Mic Anywhere on macOS?
https://medium.com/@jesse.riddle/how-in-the-bleep-do-i-mute-my-mic-anywhere-on-macos-d2fa1185b13

@bitmvr

This comment has been minimized.

Copy link

@bitmvr bitmvr commented Apr 6, 2020

@aminhusni

This comment has been minimized.

Copy link

@aminhusni aminhusni commented Apr 14, 2020

I've built an international solution that doesn't break any chat or other features. 🤞
https://github.com/MrTrick/greasemonkey-scripts/blob/master/Google%20Meet%20Hangouts%20-%20PTT.js
Hope it's helpful for someone.

This does not work

javascript: (() => {
  const toggle = tip => ({ key }) =>
    key === ' ' && document.querySelectorAll('[data-tooltip]').forEach(el => el.dataset.tooltip.includes(tip) && el.click());
  document.body.onkeyup = toggle('Turn off microphone');
  document.body.onkeydown = toggle('Turn on microphone');
})(); // fixed by @sparksm 

.includes means this works for all OSs :)

This works but chat is broken

@MrTrick

This comment has been minimized.

Copy link

@MrTrick MrTrick commented Apr 14, 2020

@aminhusni mine worked fine for me this morning. :-)
Can you tell me more about what happens and/or paste in any errors that appear in the console?
(Feel free to create an issue https://github.com/MrTrick/greasemonkey-scripts/issues )

@kennytrytek-wf

This comment has been minimized.

Copy link

@kennytrytek-wf kennytrytek-wf commented Aug 19, 2020

Current solution for Firefox:

javascript: (() => {
   const toggle = tip => ({ key }) =>
     key === ' ' && document.querySelectorAll('[data-tooltip]').forEach(el => el.dataset.tooltip === tip && el.click());
   document.body.onkeyup = toggle('Turn off microphone (⌘ + d)');
   document.body.onkeydown = toggle('Turn on microphone (⌘ + d)');
})();
@ItsJnz

This comment has been minimized.

Copy link

@ItsJnz ItsJnz commented Oct 18, 2020

This one seems to work for google meet, but the chat is broken. Does anybody have it fixed?

javascript: (() => {
const toggle = tip => ({ key }) =>
    key === ' ' && document.querySelectorAll('[aria-label]').forEach(el => el.dataset.tooltip === tip && el.click());
  document.body.onkeyup = toggle('Turn off microphone (ctrl + d)');
  document.body.onkeydown = toggle('Turn on microphone (ctrl + d)');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment