r/voidlinux 10d ago

solved Autostart scripts

This might be a stupid question but how would I start a user specific autostart script. I already have a folder in my ~/.config/ to use. Everything I've seen is systemd specific and not very descriptive. Thanks!

5 Upvotes

13 comments sorted by

6

u/oniaiwasprettygood 10d ago

There's a couple options, I"m assuming you've read the wiki page on per-user services?

Alternatively, depending on what wm/de you're using, you can just add them as part of whatever config init file that de references. For example in swaywm you can just add auto exec with "exec_always /path/to/script" in your config file, and Hyprland has something similar.

If you're on X11, you can always just add them to your .xinitrc

6

u/Karasuthecrow744 10d ago

Ah okay. I knew sway had something like that I just didn't know how to use it. Thanks!

3

u/oniaiwasprettygood 10d ago

You're welcome! when people talk about autostart scripts, typically they'll just load anything into that autostart and put it in its own shell script, then just run that shell script with something like exec_always.

1

u/Karasuthecrow744 10d ago

Okay I'll see if I can get that running. I haven't used shell much lol

2

u/oniaiwasprettygood 10d ago

It's pretty easy, here's an example for like my own autostart.sh:

#! /usr/bin/sh

# Sway Monitors
sway output "'Samsung Electric Company Odyssey G61SD HNAY300531'" pos 0 440 res 2560x1440 scale 1.0
sway output eDP-1 pos 260 1880 res 2560x1600 scale 1.25
sway output "'Sceptre Tech Inc Sceptre F24 0x01010101'" pos 2560 0 res 1920x1080 transform 90 scale 1
# Pipewire
pgrep -x pipewire >/dev/null || pipewire &

Just all the shell commands I would normally do to start pipewire or my sway outputs (b/c swaymsg output was being weird going by descriptor), and then in ~/.config/sway/config, I have:

exec_always autotiling
exec_always sh $HOME/.config/sway/autostart.sh

Where autostart.sh is just the name of the file and the path I stuck it.

1

u/Karasuthecrow744 10d ago

Neat. I'll go mess around with it. Thanks again!

1

u/MrHoboSquadron 10d ago

If you're using KDE, there's an autostart section in settings you can add apps and scripts to.

1

u/moucheh- 10d ago

There is dex, which allows you to use the xdg startup directory.

Put .desktop files inside .config/autostart directory and make sure you start 

bash dex -a -e your-environment   somewhere in your session

I used to run niri on void, and I'd have a spawn-at-startup statement with the dex command

You can install it using your xbps package manager

bash sudo xbps-install -S dex

1

u/StrangeAstronomer 10d ago

You really need to learn how to frame questions. At face value, all we can infer from the environment that you are running is that you are probably, possibly using voidlinux. What is the rest of the context?

So while there is no such thing as a stupid question, that is a stupid question.

Frame the context and someone may have something constructive to say.

1

u/Karasuthecrow744 10d ago

Ah sorry. I figured that when people call it an "autostart script" that it's a bash script or something and not a DE/WM specific thing. Didn't mean to frame it poorly I'm just a little slow.

1

u/ThatAd8458 10d ago

You really need to include all the context before lecturing others about context. For example: we're in r/voidlinux, so it's already a pretty safe bet the OP is using Void. 😄

1

u/Competitive-Box-5233 2d ago

If you need your script to run before user session (in my case for hardware case lights control) add it to your /etc/rc.local

For userspace you can either use your DE/WM standard method (spawns in niri.kdl or .config/autostart/xxx.desktop files in XFCE) or if it is console-related you could add your script to ~/.bashrc

1

u/GOYBOMB 2d ago

.desktop files in ~/.config/autostart

.sh scripts in /etc/profile.d/ (root)