Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to autostart applications the right way? #685

Closed
apinsard opened this issue Jun 28, 2015 · 10 comments
Closed

How to autostart applications the right way? #685

apinsard opened this issue Jun 28, 2015 · 10 comments

Comments

@apinsard
Copy link
Contributor

Hi, in order to get some application running on startup, I found this from the official doc and this from archlinux doc.

But none of them look elegant, nor provide a way to open application "X" on screen "N" or on group "Y".

So I tried to find other solutions to get this result. Some had no effect, some raised exceptions, but none worked.

Solution 1

@hook.subscribe.startup_once
def autostart():
    lazy.to_screen(0)
    lazy.spawn("urxvt")
    lazy.to_screen(1)
    lazy.spawn("firefox")
    lazy.to_screen(0)

Solution 2

@hook.subscribe.startup_once
def autostart():
    c = Client()
    c.to_screen(0)
    c.spawn("urxvt")
    c.to_screen(1)
    c.spawn("firefox")
    c.to_screen(0)

Solution 3

autostart.qsh

#!/usr/bin/qsh
to_screen(0)
spawn("urxvt")
to_screen(1)
spawn("firefox")
to_screen(0)

config.py

@hook.subscribe.startup_once
def autostart():
    home = os.path.expanduser('~')
    subprocess.call([home + '/.config/qtile/autostart.qsh'])

Solution 4

autostart.qsh

to_screen(0)
spawn("urxvt")
to_screen(1)
spawn("firefox")
to_screen(0)
exit

autostart.sh

#!/bin/sh
/usr/bin/qsh < /home/tony/.config/qtile/autostart.qsh

config.py

@hook.subscribe.startup_once
def autostart():
    home = os.path.expanduser('~')
    subprocess.call([home + '/.config/qtile/autostart.sh'])

None of these solutions gave results.

So how to setup my workspace properly on startup? Thanks.

@tych0
Copy link
Member

tych0 commented Jun 28, 2015

Why not use the spawn argument to Group? https://github.com/qtile/qtile-examples/blob/master/tych0/config.py#L178

@apinsard
Copy link
Contributor Author

Looks good. I didn't know about it. Thanks.

Just for the sake of completeness, is it possible to spawn more than one application per group with this technique?

@tych0
Copy link
Member

tych0 commented Jun 28, 2015

On Sun, Jun 28, 2015 at 07:29:39AM -0700, Antoine Pinsard wrote:

Looks good. I didn't know about it. Thanks.

Just for the sake of completeness, is it possible to spawn more than one application per group with this technique?

Doesn't look like it, but I don't think it would be hard to add.


Reply to this email directly or view it on GitHub:
#685 (comment)

@apinsard
Copy link
Contributor Author

Yep, could be interesting to accept a list.

@trev-dev
Copy link

trev-dev commented Dec 9, 2018

My apologies for the necro bump but just in case there's another newbie out there who's crashing their qtile while trying to fire up auto-start commands, this worked for me:

@hook.subscribe.startup_once
def autostart():
    processes = [
        ['/usr/bin/setxkbmap', '-option', 'caps:swapescape'],
        ['feh', '--bg-scale', '/home/user/Pictures/wallpaper/archfoil.jpg'],
        ['blueman-applet'],
        ['nextcloud']
    ]

    for p in processes:
        subprocess.Popen(p)

I had originally tried loading a script as per the Qtile manual but I'd either end up with a black screen or a loaded background + empty bar and nothing more. The mouse would move but the interface ends up completely broken. Here's the shell script I had attempted to use:

#! /usr/bin/bash

/usr/bin/setxkbmap -option "caps:swapescape"  &
  feh --bg-scale ~/Pictures/wallpaper/archfoil.jpg &
  blueman-applet &
  nextcloud

@tych0
Copy link
Member

tych0 commented Dec 9, 2018 via email

@tych0
Copy link
Member

tych0 commented Dec 9, 2018 via email

@trev-dev
Copy link

On Sun, Dec 09, 2018 at 09:26:17AM -0800, trevDev(); wrote: My apologies for the necro bump but just in case there's another newbie out there who's crashing their qtile while trying to fire up auto-start commands, this worked for me: python @hook.subscribe.startup_once def autostart(): processes = [ ['/usr/bin/setxkbmap', '-option', '"caps:swapescape"'] Looks like you're missing a comma here, ['feh', '--bg-scale', '~/Pictures/wallpaper/archfoil.jpg'], ['blueman-applet'], ['nextcloud'] ] for p in processes: subprocess.Popen(p) I had originally tried loading a script as per the Qtile manual but I'd either end up with a black screen or a loaded background + empty bar and nothing more. The mouse would move but the interface ends up completely broken. Here's the shell script I had attempted to use:
Probably it was because the startup_once() hook threw an exception and crashed? We should maybe add a bare except around this hook so qtile can keep booting if something bad does happen.

bash #! /usr/bin/bash /usr/bin/setxkbmap -option "caps:swapescape" & feh --bg-scale ~/Pictures/wallpaper/archfoil.jpg & blueman-applet & nextcloud -- You are receiving this because you commented. Reply to this email directly or view it on GitHub: #685 (comment)

Beg your pardon! My typos here were not in my actual config. I appreciate the sharp eyes.

@unsungNovelty
Copy link

The above didn't work exactly. So if you are coming after 04-08-2023, the below should work:

  • Setting wallpapers:
# You don't have to use feh or any other third party thing to set your wallpaper.
# Qtile has inbuilt functionality for that. 
# Set wallpaper = and wallpaper_mode inside your Screen() as shown below.
screens = [
    Screen(
        # This is the path including the file name for your wallpaper. And also set wallpaper_mode.
        wallpaper="~/Pictures/wallpapers/humpback_whale_4k_5k_hd-1920x1080.jpg",
        wallpaper_mode="fill",
        bottom=bar.Bar(
            [
                widget.CurrentLayout(),
                widget.GroupBox(),
                widget.Prompt(),
                widget.WindowName(),
            ],
            24,
            # border_width=[2, 0, 2, 0],  # Draw top and bottom borders
            # border_color=["ff00ff", "000000", "ff00ff", "000000"]  # Borders are magenta
        ),
    ),
]
  • Autostarting applications
# You should've imported the below in your config.py
import os
import subprocess
# I wrote the hook below auto minimize = True line in the default config file.
# This doesn't matter. But if you are new and confused, now you know :)
@hook.subscribe.startup_once
def autostart():
    home = os.expanduser('~/.config/qtile/autostart.sh')
    subprocess.Popen([home])

autostart.sh

#!/bin/sh
redshift-gtk &
firefox &
thunderbird &

@holocronweaver
Copy link

holocronweaver commented Jan 27, 2024

Thanks @unsungNovelty, that was handy.

However there is a bug in your autostart hook, it should use os.path.expanduser. Even better is to use Path and subprocess.run if you are on Python 3.5+ (which almost everyone is now):

# Put this in in your config.py
from pathlib import Path
import subprocess

@hook.subscribe.startup_once
def autostart():
    home = Path('~/.config/qtile/autostart.sh').expanduser()
    subprocess.run(home)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@tych0 @holocronweaver @apinsard @unsungNovelty @trev-dev and others