Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active September 21, 2023 13:55
Show Gist options
  • Save caseywatts/561bc498b6feec3d419b29a65d916663 to your computer and use it in GitHub Desktop.
Save caseywatts/561bc498b6feec3d419b29a65d916663 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link
Author

@adunkman my hero! :D

@co0l3y
Copy link

co0l3y commented Nov 2, 2017

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

@caseywatts
Copy link
Author

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
Copy link

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
Copy link

edabot commented Dec 19, 2018

Thank you, @sparksm! Worked for me.

@deanmarano
Copy link

👍 for @sparksm! works great :)

@mgohin
Copy link

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
Copy link

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
Copy link

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
Copy link

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

@MrTrick
Copy link

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
Copy link

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

@callumacrae
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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

@discentem
Copy link

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
Copy link

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#0001 or email me at [email protected]
Kind Regards!

@bitmvr
Copy link

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
Copy link

bitmvr commented Apr 6, 2020

@aminhusni
Copy link

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
Copy link

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
Copy link

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
Copy link

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