hhannine / superpaper

A cross-platform multi monitor wallpaper manager.
MIT License
1.12k stars 46 forks source link

FR: Run script each time wallpaper changes #87

Closed pekempy closed 2 years ago

pekempy commented 3 years ago

I'd like to use wal to sync terminal colours to my current wallpaper, but can't find a way to either set the current spanned wallpaper in KDE with superpaper from terminal or run a script each time superpaper changes the wallpaper.

Would it be possible to have the option to run a command/script each time the wallpaper changes?

hhannine commented 3 years ago

Maybe some type of possibility to run a script after a wallpaper change can be considered. Maybe it would be done by specifying in the settings the name of a .sh shell script file that is then run with sh?

In the meanwhile, you feasibly could monitor the temp file folder for changes in a script that then runs what you want when it sees a new file in the folder? It should be in ~/.cache/superpaper/temp, or XDG_CACHE_HOME.

pekempy commented 3 years ago

Thanks for that - I've set up inotifywait to check for newly created files for now :)

folderPath="/home/pete/.cache/superpaper/temp"
inotifywait -m $folderPath -e create | while read FILE
do
    if [[ "$FILE" =~ .*Wallpaper-a.png.* ]]
        then
            #sleep ensures the file is ready before running wal
            sleep 5
            wal -i "$folderPath/Wallpaper-a.png"
    elif [[ "$FILE" =~ .*Wallpaper-b.png.* ]]
        then
            #sleep ensures the file is ready before running wal
            sleep 5
            wal -i "$folderPath/Wallpaper-b.png"
    fi
done
hhannine commented 2 years ago

I have fixed and improved the CLI of Superpaper for next release and my thoughts are that the CLI was built exactly for use cases like this. So instead of incorporating an advanced feature like this into Superpaper, I'm thinking that the approach should be to use the Superpaper CLI inside the script that is performing other things as well. If the CLI update doesn't enable some use cases, I think we should instead look at how we can improve the CLI, instead of this script feature. At least setting the spanned wallpaper from the CLI is working on KDE now. Though I can see that being more effort from the user to setup the wal integration than to just add it onto Superpaper. One key problem with this feature is that scripting functionality is OS dependent, unless we built it to expect the script as python as well, or something like that. I can't see myself building it differently for different systems.

One option could be to include commented out hints in the source code where to add the scripting call, and advanced users could modify the source themselves to suit them?

What are your thoughts?

hhannine commented 2 years ago

I decided to implement this after all, check out the example script here: https://github.com/hhannine/superpaper/blob/master/example-script/run-after-wp-change.py Feature out in next release.