aboutsummaryrefslogtreecommitdiffstats
path: root/archive/Tak0-Autodispatch.sh
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-07-10 11:21:24 -0700
committerPinapelz <yukais@pinapelz.com>2026-07-10 11:21:24 -0700
commit24de2a31a52d17b6f7214197bdbfeab7428742dd (patch)
treef7736c4712d5a394525a3da2f2b4294e81ba9540 /archive/Tak0-Autodispatch.sh
parent861bf5be200bfcf2440fec4cda911d29ec18493f (diff)
parentbca86bbec4757cec1f6f5bdea2ed210542f10fae (diff)
Merge remote-tracking branch 'upstream'
Diffstat (limited to 'archive/Tak0-Autodispatch.sh')
-rwxr-xr-xarchive/Tak0-Autodispatch.sh68
1 files changed, 68 insertions, 0 deletions
diff --git a/archive/Tak0-Autodispatch.sh b/archive/Tak0-Autodispatch.sh
new file mode 100755
index 00000000..b0607e13
--- /dev/null
+++ b/archive/Tak0-Autodispatch.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+# ==================================================
+# KoolDots (2026)
+# Project URL: https://github.com/LinuxBeginnings
+# License: GNU GPLv3
+# SPDX-License-Identifier: GPL-3.0-or-later
+# ==================================================
+# USAGE:
+# 1) Run from terminal:
+# ./dispatch.sh <application_command> <target_workspace_number>
+# Example:
+# ./dispatch.sh discord 2
+#
+# 2) Call from Hyprland config (in hyprland.conf file):
+# exec-once = /path/to/dispatch.sh <application_command> <target_workspace_number>
+#
+# Logs are saved in dispatch.log file next to the script.
+# If the window doesn't appear or is dispatched incorrectly — info will be there.
+#
+# Notes:
+# - Script waits about ~9 seconds (30 iterations of 0.3 sec) for window to appear.
+# - Uses hyprctl and jq, so these tools must be installed.
+
+LOGFILE="$(dirname "$0")/dispatch.log"
+# Log file path located next to the script.
+
+APP=$1
+# The application command or window class to launch or match.
+
+TARGET_WORKSPACE=$2
+# The target workspace number where the window should be moved.
+
+# Check if required arguments are provided.
+if [[ -z "$APP" || -z "$TARGET_WORKSPACE" ]]; then
+ echo "Usage: $0 <application_command> <target_workspace_number>" >>"$LOGFILE" 2>&1
+ exit 1
+fi
+
+echo "Starting dispatch of '$APP' to workspace $TARGET_WORKSPACE at $(date)" >>"$LOGFILE"
+# Starting the dispatch process and logging the event.
+# Avoid early workspace focus issues by switching workspace first.
+hyprctl dispatch workspace "$TARGET_WORKSPACE" >>"$LOGFILE" 2>&1
+sleep 0.4
+
+# Launch the application in the background and disown it.
+$APP &
+disown
+pid=$!
+
+echo "Launched '$APP' with PID $pid" >>"$LOGFILE"
+# Log the launched process ID.
+# Wait for the application window to appear (matching window class).
+for i in {1..30}; do
+ win=$(hyprctl clients -j | jq -r --arg APP "$APP" '
+ .[] | select(.class | test($APP;"i")) | .address' 2>>"$LOGFILE")
+
+ if [[ -n "$win" ]]; then
+ echo "Found window $win for app '$APP', moving to workspace $TARGET_WORKSPACE" >>"$LOGFILE"
+ # Move the window to the target workspace.
+ hyprctl dispatch movetoworkspace "$TARGET_WORKSPACE,address:$win" >>"$LOGFILE" 2>&1
+ exit 0
+ fi
+ sleep 0.3
+done
+
+echo "ERROR: Window for '$APP' was NOT found or dispatched properly to workspace $TARGET_WORKSPACE at $(date)" >>"$LOGFILE"
+# Log error if window was not found or dispatched correctly.
+exit 1
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage