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
}
};
})();
@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