Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I start my computer I want that remember my applications opened before close the last session such as Ubuntu, and other distros do normally.

Googling, I see that I can run apps when I start session, configuring the autostart file but I don't want always run the same programs at start, instead I want reopen the programs opened before close last session.

I use Fedora spin with LXDE.

share|improve this question

1 Answer 1

Apparently LXDE doesn't have a proper session manager. However as you've mentioned we can use the autostart file. All we need to do is create a dynamic list of the programs we are running before we exit the desktop.

Here is a little bash script I whipped up that will parse the children of the root X11 window looking for apps to add to the autostart file. It has optional black and white lists. Use the blacklist for things like the window manager or anything you never want to run. Conversely use the whitelist for something you always want to run.

Try running it in a shell to see what the output looks like, then you can see if you need to add anything to the blacklist.

You'll need to wire this up to run somehow before you exit LXDE. Probably by adding a new entry into a menu.

For example: scriptnamehere.bash > ~/.config/lxsession/LXDE/autostart

As you can see this will rewrite the autostart file each time it is run, hence the need for the whitelist.

#!/bin/bash

WINDOWS=($(xwininfo -root -children | \
    egrep \"[a-zA-Z]*\" | \
    cut -d' ' -f7 | \
    sed 's/":\?//g' | \
    sort -du))

BLACKLIST=()
WHITELIST=()

for window in ${WINDOWS[@]}; do
    # test to see if element in array is an executable
    WHICH=$(which $window 2>/dev/null)

    # is it in the blacklist?
    # if so, move to the next window
    for app in ${BLACKLIST[@]}; do
    if [[ $app == $window ]]; then
        continue 2
    fi
    done

    # otherwise add it to the autostart list
    if [[ -f $WHICH ]]; then
        APPS[${#APPS[*]}]="$window"
    fi
done

# add whitelisted apps
for app in ${WHITELIST[@]}; do
    APPS[${#APPS[*]}]="$app"
done

for app in ${APPS[@]}; do
    printf "@%s\n" "$app"
done
share|improve this answer
    
Thank you for your script! Do you know if there's any way to save the window positions and workspaces as well? –  Glutanimate Dec 25 '12 at 3:03
    
You may be able to use the .Xresources file, depending on the application. For example to set the Geometry of an XTerm window: XTerm*Geometry: 140x50+110+60 –  vschum Jan 11 '13 at 2:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.