Config-Sway includes several utility scripts to automate common tasks and enhance your Sway experience. These scripts are located in ~/.config/scripts/ and handle autostarting applications, layout management, and wallpaper configuration.
Available Scripts
autostart.sh
Automatically launches applications in specific workspaces when Sway starts.
Location : ~/.config/scripts/autostart.sh
Features
Launches Firefox in workspace 1
Opens VSCode in workspace 2
Starts Kitty terminal in workspace 3
Includes error handling and notifications
Usage
Add to your Sway config to run on startup:
exec ~/.config/scripts/autostart.sh
How It Works
Delay Startup
Waits 2 seconds for Sway to fully initialize
Check Dependencies
Verifies swaymsg is available
Launch Applications
Opens each application in its designated workspace with 1-second delays between launches
Full Script
Customization Example
#!/usr/bin/env bash
set -euo pipefail
sleep 2
if ! command -v swaymsg > /dev/null 2>&1 ; then
notify-send "Autostart (Sway)" "swaymsg no disponible" 2> /dev/null || true
exit 0
fi
# Firefox in workspace 1
swaymsg 'workspace number 1; exec firefox' > /dev/null 2>&1 || true
sleep 1
# VSCode in workspace 2
swaymsg 'workspace number 2; exec code' > /dev/null 2>&1 || true
sleep 1
# Kitty in workspace 3
swaymsg 'workspace number 3; exec kitty' > /dev/null 2>&1 || true
mode-hacker.sh
Creates a “hacker” layout with a terminal, clock, and audio visualizer.
Location : ~/.config/scripts/mode-hacker.sh
Features
Creates a three-pane layout
Left pane: Full-height Kitty terminal
Right top: TTY-clock display
Right bottom: Cava audio visualizer
Usage
Bind to a keyboard shortcut in your Sway config:
bindsym $mod +Shift+h exec ~/.config/scripts/mode-hacker.sh
Layout Description
┌─────────────┬─────────┐
│ │ │
│ │ Clock │
│ Terminal │ │
│ ├─────────┤
│ │ │
│ │ Cava │
└─────────────┴─────────┘
Full Script
Required Packages
#!/usr/bin/env bash
set -euo pipefail
sleep 0.3
if ! command -v swaymsg > /dev/null 2>&1 ; then
notify-send "Mode hacker (Sway)" "swaymsg no disponible" 2> /dev/null || true
exit 0
fi
# Main terminal
swaymsg 'exec kitty --title x' > /dev/null 2>&1 || true
sleep 0.35
# Split horizontally and add clock
swaymsg 'split horizontal' > /dev/null 2>&1 || true
swaymsg 'exec kitty --override font_size=12 --title clock -- tty-clock -c -C 4' > /dev/null 2>&1 || true
sleep 0.35
# Split vertically and add cava
swaymsg 'split vertical' > /dev/null 2>&1 || true
swaymsg 'exec kitty --title cava -- cava' > /dev/null 2>&1 || true
Customization
You can modify the clock appearance by changing the tty-clock parameters:
-c: Center the clock
-C 4: Set color (0-7 for different colors)
-t: Display time only (no date)
-D: Display date only (no time)
setwallpaper.sh
Sets or restores the wallpaper using swaybg.
Location : ~/.config/scripts/setwallpaper.sh
Features
Reads wallpaper path from config file
Falls back to default wallpaper if not found
Uses solid color as last resort
Automatically kills existing swaybg process
Usage
Run manually or add to Sway config:
exec ~/.config/scripts/setwallpaper.sh
How It Works
Read Config
Reads wallpaper path from ~/.config/sway/wallpaper
Check File
Verifies the wallpaper file exists
Apply Wallpaper
Kills existing swaybg and launches with new wallpaper
Fallback
Uses default wallpaper or solid color if configured wallpaper not found
Full Script
Set Custom Wallpaper
#!/bin/sh
# Read wallpaper path
W = "$( cat ~/.config/sway/wallpaper 2> /dev/null || true )"
# If exists, load it
if [ -n " $W " ] && [ -f " $W " ]; then
killall swaybg 2> /dev/null || true
swaybg -i " $W " -m fill > /dev/null 2>&1 &
# Fallback to default wallpaper
elif [ -f ~ /.config/wallpapers/arch-linux-logo.webp ]; then
killall swaybg 2> /dev/null || true
swaybg -i ~/.config/wallpapers/arch-linux-logo.webp -m fill > /dev/null 2>&1 &
# Last resort: solid color
else
killall swaybg 2> /dev/null || true
swaybg -c "#1e1e2e" > /dev/null 2>&1 &
fi
Wallpaper Modes
swaybg supports several scaling modes:
fill: Scale to fill the screen (default)
fit: Scale to fit within screen
stretch: Stretch to fill screen
center: Center image without scaling
tile: Tile image across screen
Modify the script to use a different mode:
swaybg -i " $W " -m fit > /dev/null 2>&1 &
Integration with Sway Config
Add all scripts to your ~/.config/sway/config:
# Autostart applications
exec ~/.config/scripts/autostart.sh
# Set wallpaper on startup
exec ~/.config/scripts/setwallpaper.sh
# Bind hacker mode to Super+Shift+H
bindsym $mod +Shift+h exec ~/.config/scripts/mode-hacker.sh
Troubleshooting
Script Not Executing
Ensure scripts have execute permissions:
chmod +x ~/.config/scripts/ * .sh
Applications Not Launching
Check if the applications are installed:
command -v firefox
command -v code
command -v kitty
Wallpaper Not Loading
Verify swaybg is installed:
Check the wallpaper path:
cat ~/.config/sway/wallpaper
ls -la "$( cat ~/.config/sway/wallpaper)"
Creating Custom Scripts
You can create your own scripts following the same patterns:
#!/usr/bin/env bash
set -euo pipefail # Exit on error, undefined variables, pipe failures
# Check for required commands
if ! command -v swaymsg > /dev/null 2>&1 ; then
notify-send "My Script" "swaymsg not available"
exit 1
fi
# Your script logic here
swaymsg 'your commands'
Always use error handling and notifications to help debug issues.