Remix.run Logo
tincholio 2 days ago

I've been experimenting with this (it's in Babashka, which is for scripting Clojure, but you can do it with just bash, if your bash-fu is stronger than mine :D ):

    #!/bin/env bb
    
    (ns switch
      (:require [clojure.java.shell :as sh]
                [babashka.process :refer [pipeline pb shell process]]
                [clojure.string :as str]))
    
    (def workspace-ids
      (-> (pipeline (pb "hyprctl workspaces")
                    (pb "grep 'workspace ID'")
                    (pb "awk '{print $3}'"))
          last
          :out
          slurp
          (str/split #"\n")
          (->> (reduce (fn[acc e]
                         (try (let [ee (Integer/parseInt e)]
                                (conj acc ee))
                              (catch Exception e acc))) [])
               (filter #(and (pos? %)
                             (not= 10 %))))))
    
    
    
    (doseq [w workspace-ids]
      (-> (process (str "hyprctl dispatch moveworkspacetomonitor " w " 1"))
          deref
          :exit
          println))
    
    (process "hyprctl dispatch workspace 8")

It basically just moves all workspaces with positive IDs (so not the special workspace) to the external monitor, which seems to have a consistent ID of 1.