I actually use the deepl plugin for ulauncher to quickly translate texts. Unfortunately, the plugin is not really stable and I have not yet been able to find the cause. After a bit of research, I came across various tools and decided to use crow-translate.

crow-translate can be controlled via so-called dbus calls https://invent.kde.org/office/crow-translate#d-bus-api. Unfortunately, there is no MainWindow.hide or MainWindow.close in the list of possible commands. There is only the MainWindow.quit option. This closes the application completely and takes a correspondingly long time for each start. That is why I have built a corresponding helper script for my tiling window manager sway.

The helper script uses swaymsg to check whether a crow-translate window is open and then closes it using the swaymsg kill command. The kill command does NOT kill the application but it kills the window from my sway workplace 🙂. If no window is open, a window is opened using the dbus call from crow-translate.

autostart crow-translate

There are several ways to start crow-translate with the window manager. The simplest is to execute crow-translate in your sway configuration. However, the more elegant and better way is to create a systemd-user unit.

  1. navigate to ~/.config/systemd/user/

  2. create a file named crow-translate.service

    [Unit]
    Description=Crow-Translate
    Documentation=https://invent.kde.org/office/crow-translate
    After=graphical-session.target
    ConditionEnvironment=WAYLAND_DISPLAY
    
    [Service]
    Restart=always
    RestartSec=1
    ExecStart=/usr/bin/crow
    
    [Install]
    WantedBy=graphical-session.target
  3. reload your systemd configuration with systemctl --user daemon-reload

  4. enable the unit with systemctl --user enable --now crow-translate.service

the script

./config/sway/tools/crow-toggle

#!/bin/bash
# created by ♞ Raffael.Willems
if swaymsg -t get_tree | grep -q "org.kde.CrowTranslate"; then 
    swaymsg '[app_id="org.kde.CrowTranslate"] kill'
else 
    dbus-send --type=method_call --dest=org.kde.CrowTranslate /org/kde/CrowTranslate/MainWindow org.kde.CrowTranslate.MainWindow.open
fi

sway config

in you sway configuration you can then bind the script to a key with:

bindsym mod4+t exec $tools/crow-toggle

After this you can toggle the crow-translate window by pressing win+t.

Previous Post