How to launch a bash script from a conky .lua script [SOLVED]

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
User avatar
Logansfury
Level 6
Level 6
Posts: 1415
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

How to launch a bash script from a conky .lua script [SOLVED]

Post by Logansfury »

Hello everyone :)

I am working on a conky that interacts with the 4 workspaces I recently enabled.

This is a combo of conky and xdotool bash scripts to make the conky button images react to mouse-click

Problem Is I can't get the bash scripts going with a scripted start.

When I tried some edits, I put the commands to launch the scripts into the conky.text section, but this broke the script and neither the .lua file or the bash files ran:

Code: Select all

--[[
Bleys 2024 

]]
conky.config = {

-- — Conky settings

	background = false,
	total_run_times = 0,
	no_buffers = true,	

-- — Window specifications with Background

	own_window = true,
	own_window_type = dock,
    own_window_hints = 'skip_taskbar,skip_pager,undecorated,above',
    own_window_transparent = false,
	own_window_argb_visual = true,
	own_window_argb_value = 0,
	own_window_colour = '000000', 
	
	double_buffer = true,

	minimum_width = 82, minimum_height = 20,
	alignment = 'bottom_right',
	gap_x = -100,
	gap_y = -1200,

-- Lua Load
	lua_load = '/home/logansfury/.conky/Workspaces/pic.lua',
	lua_draw_hook_post = 'main',		
};
conky.text = [[
${execpi 5 ./clickbox_workspaces.sh
${execpi 5 ./clickbox_workspaces2.sh
${execpi 5 ./clickbox_workspaces3.sh
${execpi 5 ./clickbox_workspaces4.sh

]];
What code is necessary in .lua to launch 4 separate bash scripts please?

Thanks for reading,

Logan
Last edited by Logansfury on Fri Apr 12, 2024 2:12 am, edited 1 time in total.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
zcot
Level 9
Level 9
Posts: 2871
Joined: Wed Oct 19, 2016 6:08 pm

Re: How to launch a bash script from a conky .lua script

Post by zcot »

There's numerous ways that are involved so you should give more info, and/or detail, and/or more script.

You can launch a script from lua just to do a thing, for example grab some data and dump it to a file.

Or you can launch a script from lua that you expect to return some data to you so you can use it directly in a config, calling a function that brings back the data.

And maybe, at least what I'm getting out of the partial idea, you just run it from the conky config anyway.

who knows. too many unknowns there.
User avatar
Logansfury
Level 6
Level 6
Posts: 1415
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: How to launch a bash script from a conky .lua script

Post by Logansfury »

zcot wrote: Fri Apr 05, 2024 7:25 pm There's numerous ways that are involved so you should give more info, and/or detail, and/or more script.

You can launch a script from lua just to do a thing, for example grab some data and dump it to a file.

Or you can launch a script from lua that you expect to return some data to you so you can use it directly in a config, calling a function that brings back the data.

And maybe, at least what I'm getting out of the partial idea, you just run it from the conky config anyway.

who knows. too many unknowns there.
Hello Zcot,

Thank you for joining the thread! :)

I have made a conky that displays an image of 4 square buttons:

conkyrc:

Code: Select all

conky.config = {

-- — Conky settings

	background = false,
	total_run_times = 0,
	no_buffers = true,	

-- — Window specifications with Background

	own_window = true,
	own_window_type = dock,
    own_window_hints = 'skip_taskbar,skip_pager,undecorated,above',
    own_window_transparent = false,
	own_window_argb_visual = true,
	own_window_argb_value = 0,
	own_window_colour = '000000', 
	
	double_buffer = true,

	minimum_width = 82, minimum_height = 20,
	alignment = 'bottom_right',
	gap_x = -100,
	gap_y = -1200,

-- Lua Load
	lua_load = '/home/logansfury/.conky/Workspaces/pic.lua',
	lua_draw_hook_post = 'main',		
};
conky.text = [[

]];
pic.lua:

Code: Select all

--[[
2024 Bleys


]]

require 'cairo'
require "imlib2"


home_path = os.getenv ('HOME')


function fDrawImage(cr,path,xx,yy,ww,hh,arc)
    cairo_save (cr)
    local img =  cairo_image_surface_create_from_png(path)
    local w_img, h_img = cairo_image_surface_get_width(img), cairo_image_surface_get_height(img)
    cairo_translate (cr, xx, yy)
    if arc then
        cairo_rotate (cr, arc)
    end
    cairo_scale (cr, ww/w_img, hh/h_img)
    cairo_set_source_surface (cr, img, -w_img/2, -h_img/2)
    cairo_paint (cr)
    cairo_surface_destroy (img)
    collectgarbage ()
    cairo_restore (cr)
end

function conky_main()
	if conky_window==nil then return end
	local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)	
	local cr=cairo_create(cs)		
	local updates=conky_parse('${updates}')
	update_num=tonumber(updates)
  
	if update_num>4 then
        fDrawImage(cr,'/home/logansfury/Pictures/buttons.png',41,10,82,20)
	end

   cairo_surface_destroy(cs)
   cairo_destroy(cr)
end
Image

I know of no way, nor could find a way online to make these clickable but I did find online people using xdotool to make a clickable box over their conkys. This is what I have done:

clickbox_workspaces1.sh

Code: Select all

#!/bin/bash

export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
export XDG_CURRENT_DESKTOP=Cinnamon
export XDG_RUNTIME_DIR=/run/user/$(id -u)

# Define the coordinates of the clickable box
box_x=2596
box_y=1412
box_width=18
box_height=18

# Function to check if the mouse is inside the box
mouse_inside_box() {
    mouse_x=$(xdotool getmouselocation --shell | grep 'X' | awk -F'=' '{print $2}')
    mouse_y=$(xdotool getmouselocation --shell | grep 'Y' | awk -F'=' '{print $2}')

    if [ "$mouse_x" -ge "$box_x" ] && [ "$mouse_x" -le "$((box_x + box_width))" ] && \
       [ "$mouse_y" -ge "$box_y" ] && [ "$mouse_y" -le "$((box_y + box_height))" ]; then
        return 0  # Mouse is inside the box
    else
        return 1  # Mouse is outside the box
    fi
}

# Wait for a mouse click event within the specified box
while true; do
    # Get the mouse ID
    Count=$(xinput --list | grep -i 'mouse' | wc -l)
    if [[ "$Count" == 1 ]]; then
        MOUSE_ID=$(xinput --list | grep -i -m 1 'mouse' | grep -o 'id=[0-9]\+' | grep -o '[0-9]\+')
    elif [[ "$Count" -ge 2 ]]; then
        echo "Warning: We have detected two devices with xinput, we will try to use the last one."
        MOUSE_ID=$(xinput --list | grep -i 'mouse' | tail -n1 | grep -o 'id=[0-9]\+' | grep -o '[0-9]\+')
    else
        echo "Error: Mouse not detected with command: xinput --list"
        exit 1
    fi

    # Get the current state of the mouse buttons
    STATE1=$(xinput --query-state $MOUSE_ID | grep 'button\[' | sort)

    # Get the mouse button state
    MOUSE_BUTTON=$(xinput --query-state $MOUSE_ID | grep "button\[1\]=down")

    if mouse_inside_box; then
        echo "In box: Waiting for click..."
        if [[ "$MOUSE_BUTTON" != "" ]]; then
            echo "Click detected inside the box at ${mouse_x}/${mouse_y}."
            # Play a beep sound at max volume
            paplay /usr/share/sounds/freedesktop/stereo/complete.oga
            # Run switch-desk.sh 1 when mouse is clicked inside the box
            /home/logansfury/switch-desk.sh 1
        fi
    else
        echo "Location:  ${mouse_x}/${mouse_y} Square: ${box_x}-$((box_x + box_width))/${box_y}-$((box_y + box_height))"
    fi

    sleep 0.2
done
I have 4 bash scripts, each for the different location boundaries of the 4 buttons.

Is there a native way to make a conky clickable?

If I must use the bash scripts, how would I launch them please?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1415
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: How to launch a bash script from a conky .lua script

Post by Logansfury »

Has anyone any idea here since I posted my last details?

the bash scripts I need to execute are to create clickable zones over conky produced button images.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
zcot
Level 9
Level 9
Posts: 2871
Joined: Wed Oct 19, 2016 6:08 pm

Re: How to launch a bash script from a conky .lua script

Post by zcot »

I didn't really dig all that deep here.

You don't want to, I think, in my opinion, run a realtime mouse activity via a conky setup that's only firing a lua script anyway. Your timer defaults to 1 second since you didn't specify it.

I get the idea, you want 4 pics and clickable, and then process for the click.

But to do legit mouse processing you will want more than a 1 second interval on the processing activity.

You're way better off doing this differently, somehow.

BUT.

You can just fire that clickbox script from the normal conky config, and put an interval on it like infinity so it only runs once... or execp, the script itself goes into an infinite loop and is timing itself.
User avatar
zcot
Level 9
Level 9
Posts: 2871
Joined: Wed Oct 19, 2016 6:08 pm

Re: How to launch a bash script from a conky .lua script

Post by zcot »

Launch your bash script from your main conky startups script alongside firing off all the conky configs.

I decided I'm not going to show any example of firing a bash script from lua. I did look into this more, and your particular bash script here, you might just say it's a program in and of itself. It goes into a main loop. In that case, you can't do normal sequencing control that you would normally do with typical conky stuff.. -based on updates, or the timing sequences of conky's overarcing control structure. There are other case to use this type of situation, but it is not this case.

The very worse thing here would be to fire that particular bash script from lua!

First off, just so you know, look at Bley's lua script, you see where he has to parse out the first 5 iterations, he's using a counter, and the reason is due to the way when conky starts and then starts getting all the stuff set up and calling lua and then finally stabilizes on it's calls based on the internal timing interval. It's very normal, and we've see it for years, to have to parse out the conky_updates item and wait until 5 to even try to do something real.

The problem in this case is your click script shouldn't be hindered by the timing sequence of conky, it's more of a real time "program" in itself, and you just want to fire it once. But conky is running on a timing sequence. -it all doesn't match up very well.

And yes, there is not a way to make conky clickable, with the given conky stuff, it just doesn't handle that type of situation, it's a completely different thing in terms of the programming of how the conky thing works.

You can fire off a script from lua under conky, which is what you want the answer for, and do it cleanly, but you end up with a problem of dealing with way more processing to deal with than just firing your script in this specific case due to the way of that bash script creating its own main loop.. -you have to track the separated process and deal with killing that when/if conky is shut down. It's way more than should be needed here. You're gonna go way above our heads when you don't even need to.

The way to solve this issue is to fire the bash script after you have started that conky config, and you can just do it in your custom theme conky bash script that fires this set of theme configurations.
User avatar
Logansfury
Level 6
Level 6
Posts: 1415
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: How to launch a bash script from a conky .lua script

Post by Logansfury »

zcot wrote: Wed Apr 10, 2024 10:20 pm Launch your bash script from your main conky startups script alongside firing off all the conky configs.

Oh, SO far out!!

Thank you Zcot, this worked fine. I tested with 2 mp3 files for audio confirmation. I made two bash scripts that I was capable of composing without hurting myself:

ta-daa.sh

Code: Select all

#!/bin/bash

mpg123 /home/logansfury/Music/effects/ta-daa.mp3
proof.sh

Code: Select all

#!/bin/bash

mpg123 /home/logansfury/Music/effects/proof.mp3
I edited the conky-startup.sh:

Code: Select all

#!/bin/sh

if [ "$DESKTOP_SESSION" = "cinnamon" ]; then 
   sleep 20s
   killall conky
   cd "$HOME/.config/conky/Mizar"
   conky -c "$HOME/.config/conky/Mizar/Mizar no date.conf" &
   cd "$HOME/.conky/Bleys Calendar"
   conky -c "$HOME/.conky/Bleys Calendar/3-month-conkyrc" &
   cd "$HOME/.conky/Bleys Weather Header"
   conky -c "$HOME/.conky/Bleys Weather Header/wea_header.conf" &
   cd "$HOME/.conky/Bleys Weather"
   conky -c "$HOME/.conky/Bleys Weather/transparent.conf" &
   cd "$HOME/.conky/Cal Info"
   conky -c "$HOME/.conky/Cal Info/conky.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/CPU Panel.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/Fan Speeds 3M.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/GPU graph text.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/gpu.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/gpu_icon.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/hdd 3M.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/header large.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/header marque.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/memory.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor1_icon.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor2.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor2_icon.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor3.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor3_icon.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/net icon 40.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/networkpc.conky" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/processes 3M.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/temperatures 3M.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/wired public IP.conf" &
   cd "$HOME/.conky/NowPlayingConky"
   conky -c "$HOME/.conky/NowPlayingConky/audacious.conf" &
   cd "$HOME/.conky/NowPlayingConky"
   conky -c "$HOME/.conky/NowPlayingConky/rhythmbox.conf" &
   cd "$HOME/.conky/Server"
   conky -c "$HOME/.conky/Server/conky.conf" &
   cd "$HOME/.conky/Workspaces"
   conky -c "$HOME/.conky/Workspaces/box.conf" &
   cd "$HOME/.conky/Workspaces"
   conky -c "$HOME/.conky/Workspaces/conkyrc" &
   cd "$HOME/.conky/m3_clock"
   conky -c "$HOME/.conky/m3_clock/conkyrc" &
   cd "$HOME/.conky/qclocktwo"
   conky -c "$HOME/.conky/qclocktwo/conkyrc" &
   /home/logansfury/Desktop/ta-daa.sh
    sleep 3
    /home/logansfury/Desktop/proof.sh
   exit 0
fi

I logged out and back in, and both mp3's fired properly with the 3 second pause between. I will just replace these test bash scripts with the scripts that create the clickable boxes.

Thank you so much :)
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
zcot
Level 9
Level 9
Posts: 2871
Joined: Wed Oct 19, 2016 6:08 pm

Re: How to launch a bash script from a conky .lua script

Post by zcot »

So now what?

You have that clickbox mouse program running, but it's only coded to switch to one situation, correct? and not back, or to another workspace conky theme. But, it's still running in the background.

If you start it again with another switch-desk activity then you would have 2 of the clickbox bash scripts, so not a good setup.

If you create different clickbox action scripts based on each conky workspace theme, then you need to kill the previous clickbox script when you enter a new phase. Or edit the script to where it will switch to any of the choices that are available at any given time

On a different note, you can't do those tweaks of the conky-startup.sh file because it gets overwritten, you can't add custom lines like that. You can use that file but you have to rename it, or move it out of the conky system path, and then you are starting it yourself manually in some way.

So now where do you stand?
User avatar
Logansfury
Level 6
Level 6
Posts: 1415
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: How to launch a bash script from a conky .lua script

Post by Logansfury »

zcot wrote: Thu Apr 11, 2024 7:29 am So now what?

You have that clickbox mouse program running, but it's only coded to switch to one situation, correct? and not back, or to another workspace conky theme. But, it's still running in the background.

If you start it again with another switch-desk activity then you would have 2 of the clickbox bash scripts, so not a good setup.

If you create different clickbox action scripts based on each conky workspace theme, then you need to kill the previous clickbox script when you enter a new phase. Or edit the script to where it will switch to any of the choices that are available at any given time

On a different note, you can't do those tweaks of the conky-startup.sh file because it gets overwritten, you can't add custom lines like that. You can use that file but you have to rename it, or move it out of the conky system path, and then you are starting it yourself manually in some way.

So now where do you stand?
The conky start file overwriting itself and eliminating my edit is not something I had considered. I guess I will have to abandon my idea for this conky and just use my existing hotkey combos to launch switch-desk scripts by themselves. Those are still switching conky arrays when I wish although they dont always restore the array completely and I have to open CM2 and manually enable what got skipped over.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1415
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: How to launch a bash script from a conky .lua script

Post by Logansfury »

zcot wrote: Thu Apr 11, 2024 7:29 am So now where do you stand?
Still a very stubborn Italian-American.

I got with the online resources, which can be so frustrating they can make you wish you could take a Valium, and saw what I could generate in python3

It took asking the same questions over and over and delivering blistering profanities thru my keyboard, but I wound up with this:

Image

This lovely little windowless button bar upon launch detects workspace and colors the corresponding button red, matching the feature of the cinnamon applet workspace switcher, but these buttons launch my switch-desk scripts that set conky array, wallpaper, wallpaper scrolling if applicable etc, which the workspace switcher could not do.

Here is the python script:

buttons3.py

Code: Select all

import tkinter as tk
import subprocess

def button_click(btn_num):
    global last_clicked_button
    if last_clicked_button:
        last_clicked_button.config(bg=default_color)  # Reset color of previously clicked button
    button = buttons[btn_num-1]
    button.config(bg="red")  # Set background color to red for the clicked button
    last_clicked_button = button
    # Execute the script associated with the clicked button
    scripts[btn_num-1]()

def script_1():
    # Put your script for button 1 here
   subprocess.call(['/home/logansfury/switch-desk-1.sh']) 
   print("Script for Button 1 executed")

def script_2():
    # Put your script for button 2 here
   subprocess.call(['/home/logansfury/switch-desk-2.sh']) 
   print("Script for Button 2 executed")

def script_3():
    # Put your script for button 3 here
   subprocess.call(['/home/logansfury/switch-desk-3.sh']) 
   print("Script for Button 3 executed")

def script_4():
    # Put your script for button 4 here
   subprocess.call(['/home/logansfury/switch-desk-4.sh']) 
   print("Script for Button 4 executed")

root = tk.Tk()
root.title("Workspaces") # Name the window
root.geometry("+2350+1350")  # Set the window position

# Set window type to dock
root.wm_attributes("-type", "dock")

buttons = []
last_clicked_button = None
default_color = root.cget("bg")  # Get default background color of buttons

# Define scripts for each button
scripts = [script_1, script_2, script_3, script_4]

# Get the current workspace number using xdotool
try:
    current_workspace = int(subprocess.check_output(["xdotool", "get_desktop"]).decode().strip()) + 1
except subprocess.CalledProcessError:
    current_workspace = None

# Create buttons
for i in range(1, 5):
    if i == current_workspace:
        button = tk.Button(root, text=str(i), width=3, command=lambda num=i: button_click(num), bg="red")
        last_clicked_button = button
    else:
        button = tk.Button(root, text=str(i), width=3, command=lambda num=i: button_click(num))
    button.grid(row=0, column=i-1)
    buttons.append(button)

root.mainloop()
Here is my new switch-desk-1.sh bash edited for the python buttons:

Code: Select all

#!/bin/bash

    pkill -f buttons3.py

    sleep 2s

    /home/logansfury/switch-desk.sh 1 

    sleep 2s

VRESULT=$(wmctrl -l | grep Header)

if [[ "$VRESULT" ]]; then
    echo "conky widget Header detected by script"
    mpg123 /home/logansfury/Music/effects/minimalis_enabled.mp3
else
   killall conky
   cd "$HOME/.config/conky/Mizar"
   conky -c "$HOME/.config/conky/Mizar/Mizar no date.conf" &
   cd "$HOME/.conky/Bleys Calendar"
   conky -c "$HOME/.conky/Bleys Calendar/3-month-conkyrc" &
   cd "$HOME/.conky/Bleys Weather Header"
   conky -c "$HOME/.conky/Bleys Weather Header/wea_header.conf" &
   cd "$HOME/.conky/Bleys Weather"
   conky -c "$HOME/.conky/Bleys Weather/transparent.conf" &
   cd "$HOME/.conky/Cal Info"
   conky -c "$HOME/.conky/Cal Info/conky.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/CPU Panel.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/Fan Speeds 3M.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/GPU graph text.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/gpu.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/gpu_icon.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/hdd 3M.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/header large.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/header marque.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/memory.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor1_icon.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor2.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor2_icon.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor3.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/monitor3_icon.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/net icon 40.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/networkpc.conky" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/processes 3M.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/temperatures 3M.conf" &
   cd "$HOME/.conky/Minimalis Conky"
   conky -c "$HOME/.conky/Minimalis Conky/wired public IP.conf" &
   cd "$HOME/.conky/NowPlayingConky"
   conky -c "$HOME/.conky/NowPlayingConky/audacious.conf" &
   cd "$HOME/.conky/NowPlayingConky"
   conky -c "$HOME/.conky/NowPlayingConky/rhythmbox.conf" &
   cd "$HOME/.conky/Server"
   conky -c "$HOME/.conky/Server/conky.conf" &
   cd "$HOME/.conky/Workspaces"
   conky -c "$HOME/.conky/Workspaces/conkyrc" &
   cd "$HOME/.conky/Workspaces"
   conky -c "$HOME/.conky/Workspaces/clickboxes" &
   cd "$HOME/.conky/m3_clock"
   conky -c "$HOME/.conky/m3_clock/conkyrc" &
   cd "$HOME/.conky/qclocktwo"
   conky -c "$HOME/.conky/qclocktwo/conkyrc" &
fi
   sleep 2s

    /home/logansfury/xdotool/start_python.sh
    sleep 1s
    /home/logansfury/python_work/workspace_1_wp.sh
Here is the start_python.sh which I found necessary, as starting it directly from the above script caused it to hang:

Code: Select all

#!/bin/bash

python3 /home/logansfury/python_work/buttons3.py
The scripts kill the running python script before changing workspaces to avoid leaving scripts running on unattended workspaces and reducing cpu load.

Whatcha think Zcot?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
zcot
Level 9
Level 9
Posts: 2871
Joined: Wed Oct 19, 2016 6:08 pm

Re: How to launch a bash script from a conky .lua script

Post by zcot »

Ha! wholly hell!

now, that's getting into it a lot better at this point!
User avatar
Logansfury
Level 6
Level 6
Posts: 1415
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: How to launch a bash script from a conky .lua script

Post by Logansfury »

I did more work with the resources, and I got the numbers in my system font, and found code to lift it above the bottom panel, allowing it to be positioned superimposed over the panel. When completely superimposed, the panel cannot be clicked (evidently lifting it allows its visible screen position to overlap the bottom panel, yet the panel is still atop it and blocking its buttons), so I have it half superimposed over bottom panel and can activate it from the top half while it still looks clean and tucked into the GUI:

Image

python script:

Code: Select all

import tkinter as tk
import subprocess

def button_click(btn_num):
    global last_clicked_button
    if last_clicked_button:
        last_clicked_button.config(bg=default_color)  # Reset color of previously clicked button
    button = buttons[btn_num-1]
    button.config(bg="red")  # Set background color to red for the clicked button
    last_clicked_button = button
    # Execute the script associated with the clicked button
    scripts[btn_num-1]()

def script_1():
    # Put your script for button 1 here
   subprocess.call(['/home/logansfury/switch-desk-1.sh']) 
   print("Script for Button 1 executed")

def script_2():
    # Put your script for button 2 here
   subprocess.call(['/home/logansfury/switch-desk-2.sh']) 
   print("Script for Button 2 executed")

def script_3():
    # Put your script for button 3 here
   subprocess.call(['/home/logansfury/switch-desk-3.sh']) 
   print("Script for Button 3 executed")

def script_4():
    # Put your script for button 4 here
   subprocess.call(['/home/logansfury/switch-desk-4.sh']) 
   print("Script for Button 4 executed")

root = tk.Tk()
root.title("Workspaces") # Name the window
root.geometry("+2280+1380")  # Set the window position

# Set window type to dock
root.wm_attributes("-type", "dock")

buttons = []
last_clicked_button = None
default_color = root.cget("bg")  # Get default background color of buttons

# Define scripts for each button
scripts = [script_1, script_2, script_3, script_4]

# Get the current workspace number using xdotool
try:
    current_workspace = int(subprocess.check_output(["xdotool", "get_desktop"]).decode().strip()) + 1
except subprocess.CalledProcessError:
    current_workspace = None

# Define font for the button numbers
button_font = ("Neon 80s", 12, "bold")

# Create buttons
for i in range(1, 5):
    if i == current_workspace:
        button = tk.Button(root, text=str(i), width=3, command=lambda num=i: button_click(num), bg="red")
        last_clicked_button = button
    else:
        button = tk.Button(root, text=str(i), width=3, command=lambda num=i: button_click(num))
    button.config(font=button_font)  # Set font for button text
    button.grid(row=0, column=i-1)
    buttons.append(button)

# Lift the button array above the bottom panel
for btn in buttons:
    btn.lift()

root.mainloop()
Last edited by Logansfury on Thu Apr 11, 2024 9:51 pm, edited 1 time in total.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1415
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: How to launch a bash script from a conky .lua script

Post by Logansfury »

zcot wrote: Thu Apr 11, 2024 8:09 pm Ha! wholly hell!

now, that's getting into it a lot better at this point!
May I ask your opinion of the script's safety to my system Zcot?

I know coming from online resources, this is scripted in a straightforward, brute-force style lacking the elegance of human ingenuity for creative shortcuts. But is the final result a monstrosity that will cause undo load on my system, or have I got it reasonably controlled by closing the script on each workspace switch to ensure it is always only running on one workspace?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 6
Level 6
Posts: 1415
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: How to launch a bash script from a conky .lua script

Post by Logansfury »

I just spent another hour with the resources and I got a combo script that is firing BOTH loops, the wallpaper changer on workspace 1 only, and the button bar waiting for click on all 4 workspaces:

combo.py

Code: Select all

import tkinter as tk
import subprocess
import threading
import time

def button_click(btn_num):
    global last_clicked_button
    if last_clicked_button:
        last_clicked_button.config(bg=default_color)  # Reset color of previously clicked button
    button = buttons[btn_num-1]
    button.config(bg="red")  # Set background color to red for the clicked button
    last_clicked_button = button
    # Execute the script associated with the clicked button
    scripts[btn_num-1]()

def script_1():
    # Put your script for button 1 here
    subprocess.call(['/home/logansfury/switch-desk-1plus.sh']) 
    print("Script for Button 1 executed")

def script_2():
    # Put your script for button 2 here
    subprocess.call(['/home/logansfury/switch-desk-2plus.sh']) 
    print("Script for Button 2 executed")

def script_3():
    # Put your script for button 3 here
    subprocess.call(['/home/logansfury/switch-desk-3plus.sh']) 
    print("Script for Button 3 executed")

def script_4():
    # Put your script for button 4 here
    subprocess.call(['/home/logansfury/switch-desk-4plus.sh']) 
    print("Script for Button 4 executed")

def wallpaper_changer():
    wallpapers = [
        'file:///home/logansfury/Pictures/Best_WP/7680x1440attribution.jpg',
        'file:///home/logansfury/Pictures/Best_WP/7680x1440planets.jpg',
        'file:///home/logansfury/Pictures/Best_WP/7680x1440space3.jpg',
        'file:///home/logansfury/Pictures/7680x1440forest.jpg',
        'file:///home/logansfury/Pictures/Best_WP/mtnlake2.jpg',
        'file:///home/logansfury/Pictures/Best_WP/bikini.jpg',
        'file:///home/logansfury/Pictures/Best_WP/blonde.jpg',
        'file:///home/logansfury/Pictures/Best_WP/m3_color.jpg',
        'file:///home/logansfury/Pictures/Best_WP/m3_b&w.jpg',
        'file:///home/logansfury/Pictures/Best_WP/purp.jpg',
        'file:///home/logansfury/Pictures/Best_WP/greyblue.jpg',
        'file:///home/logansfury/Pictures/Best_WP/wolf0.jpg',
        'file:///home/logansfury/Pictures/Best_WP/wolf1.jpg',
        'file:///home/logansfury/Pictures/Best_WP/wolves1.jpg'
    ]
    # Play scrolling sound if on workspace 1
    if int(subprocess.check_output(["xdotool", "get_desktop"]).decode().strip()) == 0:
        subprocess.call(['mpg123', '/home/logansfury/Music/effects/scrolling.mp3'])
        while True:
            for wallpaper in wallpapers:
                # Check if the workspace is equal to 1
                if int(subprocess.check_output(["xdotool", "get_desktop"]).decode().strip()) == 0:
                    subprocess.call(['gsettings', 'set', 'org.cinnamon.desktop.background', 'picture-uri', wallpaper])
                    subprocess.call(['gsettings', 'set', 'org.cinnamon.desktop.background', 'picture-options', 'spanned'])
                else:
                    # If the workspace is not 1, exit the script
                    print("Workspace is not 1. Exiting script.")
                    subprocess.call(['/home/logansfury/Music/effects/workspace_changed.mp3'])
                    return
                time.sleep(60)
    else:
        print("Not on workspace 1. Exiting script.")

root = tk.Tk()
root.title("Workspaces") # Name the window
root.geometry("+2280+1380")  # Set the window position

# Set window type to dock
root.wm_attributes("-type", "dock")

buttons = []
last_clicked_button = None
default_color = root.cget("bg")  # Get default background color of buttons

# Define scripts for each button
scripts = [script_1, script_2, script_3, script_4]

# Define font for the button numbers
button_font = ("Neon 80s", 12)

# Create buttons
for i in range(1, 5):
    button = tk.Button(root, text=str(i), width=3, command=lambda num=i: button_click(num))
    button.config(font=button_font)  # Set font for button text
    button.grid(row=0, column=i-1)
    buttons.append(button)

# Get the current workspace number using xdotool
try:
    current_workspace = int(subprocess.check_output(["xdotool", "get_desktop"]).decode().strip()) + 1
except subprocess.CalledProcessError:
    current_workspace = None

# Set the initial color of the button for the current workspace
if current_workspace:
    buttons[current_workspace - 1].config(bg="red")
    last_clicked_button = buttons[current_workspace - 1]

# Lift the button array above the bottom panel
for btn in buttons:
    btn.lift()

# Start the wallpaper changer in a separate thread
wallpaper_thread = threading.Thread(target=wallpaper_changer)
wallpaper_thread.start()

root.mainloop()
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
Post Reply

Return to “Compiz, Conky, Docks & Widgets”