singularity~ 0 Newbie Poster

How can I open an application on a specific workspace using the terminal in UNIX?

**** I cannot use any external addons like Devil's Pie ****

Dani AI

Generated

— There is no single, “Unix-wide” terminal flag to tell every desktop to open an app on workspace N. Virtual desktops are a feature of the window manager/compositor, so the reliable approaches are WM-specific (X11/EWMH tools, tiling-WM IPC, or compositor APIs). (specifications.freedesktop.org)

If you use a tiling WM with an IPC interface you can start an app on a workspace in one shot. Example (i3, X11):

i3-msg 'workspace 3; exec firefox'

And on Sway (Wayland) the same idea with swaymsg:

swaymsg 'workspace 3; exec firefox'

These use the WM’s own commands and are the least fragile option. (i3wm.org)

For classic X11 desktops without a built-in “exec on workspace” you can launch the program, detect its window, then move it with EWMH tools. A robust pattern is: start the program, wait for its window (search by PID/class), then move it. Example (requires xdotool + wmctrl):

#!/bin/bash
myapp & pid=$!
for i in {1..30}; do
  win=$(xdotool search --pid $pid --onlyvisible 2>/dev/null | head -n1)
  [ -n "$win" ] && break
  sleep 0.1
done
[ -z "$win" ] && exit 1
wmctrl -i -r "$win" -t 2   # desktops are 0-based in wmctrl

That handles race conditions; use precise matching (--class/--name/--pid) for reliability. (manpages.debian.org)

If you run KDE/Plasma, kstart --desktop N <cmd> or KWin window rules (System Settings → Window Management → Window Rules) are often the cleanest. On Wayland sessions many X11 tools (xdotool/wmctrl) do not work — compositor-specific APIs or extensions are required (GNOME removed some Eval hooks; small extensions or compositor IPC are the replacement). If you cannot install extra helpers, prefer the WM’s native rules/config. (man.cx)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.