Running cron jobs for Sway

Use cron to schedule scripts that interact with Sway using swaymsg.

#!/bin/sh

set -eu

uid="$(id -u)"

for sock in /run/user/"${uid}"/sway-ipc.*.*.sock; do
    [ -S "${sock}" ] || continue
    swaymsg -s "${sock}" exec -- "$@"
done

Useful for when you run a script that interacts with D-Bus. An example could be using notify-send.

* * * * * $HOME/.local/bin/sway-exec /bin/notify-send 'Hello'

Resources