Last active
August 29, 2025 22:02
-
-
Save bulletmark/8e051a0a9ffdce689d86988c528e7764 to your computer and use it in GitHub Desktop.
Revisions
-
bulletmark revised this gist
Aug 29, 2025 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ # (i.e. `sudo chmod 755 /etc/NetworkManager/dispatcher.d/99-wifi`). No other # configuration is required. Get the latest version from # https://gist.github.com/bulletmark/8e051a0a9ffdce689d86988c528e7764 # Python 3.7 or later is required. # Author: Mark Blakeney, Jun 2020. from __future__ import annotations import subprocess @@ -14,8 +15,7 @@ import sys def run(cmd: str) -> list[str]: 'Run given cmd' try: res = subprocess.run(cmd.split(), stdout=subprocess.PIPE, text=True) except Exception as e: sys.exit(str(e)) -
bulletmark revised this gist
Mar 1, 2025 . 1 changed file with 6 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,10 @@ #!/usr/bin/env python3 # If you are using Linux NetworkManager then this dispatcher script toggles # your wifi radio ON whenever all your wired connections are not connected, or # turns the wifi radio OFF when any wired connection is connected. Simply copy # this to /etc/NetworkManager/dispatcher.d/99-wifi and ensure it is executable # (i.e. `sudo chmod 755 /etc/NetworkManager/dispatcher.d/99-wifi`). No other # configuration is required. Get the latest version from # https://gist.github.com/bulletmark/8e051a0a9ffdce689d86988c528e7764 # Author: Mark Blakeney, Jun 2020. from __future__ import annotations -
bulletmark revised this gist
Jun 11, 2024 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,11 @@ #!/usr/bin/env python3 # If you are using Linux NetworkManager then this program toggles your # wifi radio on whenever all your wired connections are not connected, # or turns the wifi radio off when any wired connection is connected. # Simply copy this to /etc/NetworkManager/dispatcher.d/99-wifi and # ensure it is executable # (i.e. `sudo chmod 755 /etc/NetworkManager/dispatcher.d/99-wifi`). # No other configuration is required. Get the latest version from # https://gist.github.com/bulletmark/8e051a0a9ffdce689d86988c528e7764 # Author: Mark Blakeney, Jun 2020. from __future__ import annotations -
bulletmark revised this gist
Jun 11, 2024 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,10 +7,11 @@ # No configuration is required. Get the latest version from # https://gist.github.com/bulletmark/8e051a0a9ffdce689d86988c528e7764 # Author: Mark Blakeney, Jun 2020. from __future__ import annotations import subprocess import sys def run(cmd: str) -> list[str]: 'Run given cmd' try: res = subprocess.run(cmd.split(), stdout=subprocess.PIPE, -
bulletmark revised this gist
Jun 11, 2024 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,11 +7,10 @@ # No configuration is required. Get the latest version from # https://gist.github.com/bulletmark/8e051a0a9ffdce689d86988c528e7764 # Author: Mark Blakeney, Jun 2020. import subprocess import sys def run(cmd: str): 'Run given cmd' try: res = subprocess.run(cmd.split(), stdout=subprocess.PIPE, -
bulletmark revised this gist
Jun 11, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ # wifi connection off->ON whenever your wired connection goes ON->off, # and vice-versa. Simply copy this to # /etc/NetworkManager/dispatcher.d/99-wifi and ensure it is executable. # (i.e. `sudo chmod 755 /etc/NetworkManager/dispatcher.d/99-wifi`). # No configuration is required. Get the latest version from # https://gist.github.com/bulletmark/8e051a0a9ffdce689d86988c528e7764 # Author: Mark Blakeney, Jun 2020. -
bulletmark revised this gist
Jan 2, 2024 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,8 +21,7 @@ def run(cmd: str) -> list[str]: if res.returncode != 0: sys.exit(res.returncode) return res.stdout.strip().splitlines() # Firstly, ensure airplane mode is off because GNOME has an unfortunate # habit of automatically turning it on. -
bulletmark revised this gist
Jan 2, 2024 . 1 changed file with 10 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,32 @@ #!/usr/bin/env python3 # If you are using Linux NetworkManager then this program toggles your # wifi connection off->ON whenever your wired connection goes ON->off, # and vice-versa. Simply copy this to # /etc/NetworkManager/dispatcher.d/99-wifi and ensure it is executable. # No configuration is required. Get the latest version from # https://gist.github.com/bulletmark/8e051a0a9ffdce689d86988c528e7764 # Author: Mark Blakeney, Jun 2020. from __future__ import annotations import subprocess import sys def run(cmd: str) -> list[str]: 'Run given cmd' try: res = subprocess.run(cmd.split(), stdout=subprocess.PIPE, universal_newlines=True) except Exception as e: sys.exit(str(e)) if res.returncode != 0: sys.exit(res.returncode) out = res.stdout and res.stdout.strip() return out.splitlines() if out else [] # Firstly, ensure airplane mode is off because GNOME has an unfortunate # habit of automatically turning it on. for line in run('rfkill -n'): devid, devtype, pdev, sstate, hstate = line.split() if devtype == 'wlan' and sstate == 'blocked': run(f'rfkill unblock {devid}') @@ -33,7 +35,7 @@ eth_up = False wifi_up = None # Look at current state for line in run('nmcli -t -c no device'): dev, devtype, state, *junk = line.split(':') if devtype == 'ethernet': if state == 'connected': -
bulletmark revised this gist
Oct 2, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,8 @@ def run(cmd): return res.stdout # Firstly, ensure airplane mode is off because GNOME has an unfortunate # habit of automatically turning it on. for line in run('rfkill -n').splitlines(): devid, devtype, pdev, sstate, hstate = line.split() if devtype == 'wlan' and sstate == 'blocked': -
bulletmark revised this gist
Sep 18, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def run(cmd): return res.stdout # Firstly, ensure airplane mode is off for line in run('rfkill -n').splitlines(): devid, devtype, pdev, sstate, hstate = line.split() if devtype == 'wlan' and sstate == 'blocked': -
bulletmark revised this gist
Sep 18, 2020 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ # No configuration is required. Get the latest version from # https://gist.github.com/bulletmark/8e051a0a9ffdce689d86988c528e7764 # Author: Mark Blakeney, Jun 2020. import sys import subprocess def run(cmd): @@ -22,9 +22,16 @@ def run(cmd): return res.stdout # Ensure Airplane mode is off for line in run('rfkill -n').splitlines(): devid, devtype, pdev, sstate, hstate = line.split() if devtype == 'wlan' and sstate == 'blocked': run(f'rfkill unblock {devid}') eth_up = False wifi_up = None # Look at current state for line in run('nmcli -t -c no device').splitlines(): dev, devtype, state, *junk = line.split(':') if devtype == 'ethernet': -
bulletmark revised this gist
Sep 4, 2020 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ #!/usr/bin/python3 # If you are using Linux NetworkManager then this program toggles your # wifi connection off->ON whenever your wired connection goes ON->off, # and vice-versa. Simply copy this to # /etc/NetworkManager/dispatcher.d/99-wifi and ensure it is executable. # No configuration is required. Get the latest version from # https://gist.github.com/bulletmark/8e051a0a9ffdce689d86988c528e7764 # Author: Mark Blakeney, Jun 2020. import sys -
bulletmark revised this gist
Jul 30, 2020 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,9 @@ # If you are using Linux NetworkManager then this program toggles your # wifi connection off/ON whenever your wired connection goes ON/off. # Simply copy this to /etc/NetworkManager/dispatcher.d/99-wifi and # ensure it is executable. No configuration is required. Get the latest # version from # https://gist.github.com/bulletmark/8e051a0a9ffdce689d86988c528e7764 # Author: Mark Blakeney, Jun 2020. import sys import subprocess -
bulletmark created this gist
Jul 7, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ #!/usr/bin/python3 # If you are using Linux NetworkManager then this program toggles your # wifi connection off/ON whenever your wired connection goes ON/off. # Simply copy this to /etc/NetworkManager/dispatcher.d/99-wifi and # ensure it is executable. No configuration is required. # Author: Mark Blakeney, Jun 2020. import sys import subprocess def run(cmd): 'Run given cmd' try: res = subprocess.run(cmd.split(), stdout=subprocess.PIPE, universal_newlines=True) except Exception as e: sys.exit(str(e)) if res.returncode != 0: sys.exit(res.returncode) return res.stdout eth_up = False wifi_up = None for line in run('nmcli -t -c no device').splitlines(): dev, devtype, state, *junk = line.split(':') if devtype == 'ethernet': if state == 'connected': eth_up = True elif devtype == 'wifi': if state == 'connected': wifi_up = True elif wifi_up is None: wifi_up = False # Set wifi off/on if ethernet device on/off. # Note we only switch wifi off/on if wifi device exists. if eth_up: if wifi_up: run('nmcli radio wifi off') else: if wifi_up is False: run('nmcli radio wifi on')