Skip to content

CLI usage without Gnome environment

Nebulosa edited this page Apr 21, 2024 · 13 revisions

We can use gsconnect without Gnome installed, this page explains how to do it for general wayland environment.

Preparations

  1. Build libgnome-volume-control, which is a subproject of gnome-shell but can be built independently;
  2. Install ydotool and add current user to the input group, and start its service: systemctl start --user ydotool.service;
  3. Install wtype and wl-clipboard;
  4. Install gjs, which is the runtime of gsconnect.

Install gsconnect

  1. Clone this repo;
  2. Build and install it: meson build, ninja -C build install-zip;
  3. For systemd, make the .service file for user: ~/.config/systemd/user/gsconnect.service or /usr/lib/systemd/user/gsconnect.service:
[Unit]
Description=GSConnect CLI
Documentation=https://github.com/GSConnect/gnome-shell-extension-gsconnect/wiki/CLI-usage-without-Gnome-environment
PartOf=graphical-session.target
After=graphical-session.target
Requisite=graphical-session.target

[Service]
ExecStart=/usr/share/gnome-shell/extensions/[email protected]/service/daemon.js
Restart=on-failure

[Install]
WantedBy=graphical-session.target
  1. If gsconnect.service is located at /usr/lib/systemd/user/gsconnect.service gsconnect can be loaded automatically through dbus by request thought indicator described below or manually on click Refresh button in gsconnect-preferences.

Hint: to see status started service by dbus, you should use systemctl status --user dbus-:[email protected]

Indicator of gsconnect

For example, with waybar and hack nerd font, one can do the following steps.

Script to fetch gsconnect status

Save the following script to ~/.config/waybar/gsconnect-status.py.

#! python3
from pydbus import SessionBus
import json

session_bus = SessionBus()
proxy_gsconnect = session_bus.get(
    'org.gnome.Shell.Extensions.GSConnect',
    '/org/gnome/Shell/Extensions/GSConnect')
gsconnect = proxy_gsconnect[
    'org.freedesktop.DBus.ObjectManager']

waybar = {'text': "", 'tooltip': "", "class": "GSdevices", "types": ""}

icons = {'smartphone-symbolic': "󰄜", "tablet-symbolic": "",
         'tv-symbolic': "", 'computer-symbolic': ""}

types = []
devices = gsconnect.GetManagedObjects()
for dev in devices:
    devinfo = devices[dev]['org.gnome.Shell.Extensions.GSConnect.Device']
    if devinfo['Connected']:
        if devinfo['Paired']:
            types.append(devinfo['Type'])
            waybar['text'] += icons[devinfo['IconName']] + ' '
            waybar['tooltip'] += devinfo['Name'] + '\n'
        if not devinfo['Paired']:
            types.append(devinfo['Type'])
            waybar['text'] += ' ' + ' '
            waybar['tooltip'] += devinfo['Name'] + '\n'

waybar['types'] = '+'.join(types)
for key in waybar:
    waybar[key] = waybar[key].strip()

print(json.dumps(waybar))

Install pydbus and test the above script to ensure that there is no problem.

Add waybar module

In this step, we assume that you know how to config waybar custom module. If not, see the waybar manual page for instructions. See the examplar config.

Add waybar the custom module:

"custom/gsconnect" : {
  "format": "{}",
  "escape": true,
  "exec": "python3 $HOME/.config/waybar/gsconnect-status.py",
  "return-type": "json",
  "tooltip": "{tooltip}",
  "interval": 30,
  "on-click": "/usr/share/gnome-shell/extensions/[email protected]/gsconnect-preferences"
}