Skip to content

Instantly share code, notes, and snippets.

@tana
Created March 13, 2022 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tana/6539197cbe0a3658bb8ac67140a780b9 to your computer and use it in GitHub Desktop.
Save tana/6539197cbe0a3658bb8ac67140a780b9 to your computer and use it in GitHub Desktop.
systemdを使ってBluetoothデバイスに自動接続する

Linuxの起動時にBluetoothデバイス(ゲームパッドなど)に自動接続するsystemd Unitです。 デバイスは事前にbluetoothctlでペアリングしておく必要あり。 <MAC_ADDRESS> は接続先BluetoothデバイスのMACアドレス(例:AB:CD:EF:12:34:56)に置き換えてください。

[Unit]
Description=Bluetooth Device Auto-connect
After=bluetooth.service
Requires=bluetooth.service
[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/usr/bin/bluetoothctl -- connect D4:F0:57:67:DA:72
ExecStop=/usr/bin/bluetoothctl -- disconnect D4:F0:57:67:DA:72
# Retry until connection succeeds
Restart=on-failure
StartLimitIntervalSec=0
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment