need help with conky .lua script please [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 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

need help with conky .lua script please [SOLVED]

Post by Logansfury »

Hello everyone,

I am trying to use conky to display a random image and play a corresponding .mp3 file with mpg123.

I have a directory with .png files numbered 1-51.png and a directory of .mp3 files named 1-51.mp3

Here is the conf:

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 = 324, minimum_height = 214,
	alignment = 'middle_middle',
	
	gap_x = 20,
	gap_y = 20,

    update_interval = 3600,

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

]];
and here is the .lua

Code: Select all

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)
        math.randomseed(os.time())
        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
       --end
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
Currently what I have works. It randomizes a different number every time, and is showing the .png file.
Now I need an edit for mpg123 to navigate to /home/logansfury/Music/eyegor/ and play the $random_number .mp3

Can anyone provide code to help?

Thanks for reading,

Logan
Last edited by Logansfury on Thu May 16, 2024 7:47 pm, edited 1 time in total.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
zcot
Level 9
Level 9
Posts: 2957
Joined: Wed Oct 19, 2016 6:08 pm

Re: need help with conky .lua script please

Post by zcot »

look at the last 6 lines of the .lua file:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
       --end
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
but it should look like these 5 lines instead:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
now make it look like that:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
        local dangler = io.popen('some bash command goes here')
        dangler:close()
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: need help with conky .lua script please

Post by Logansfury »

zcot wrote: Wed May 15, 2024 5:55 pm look at the last 6 lines of the .lua file:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
       --end
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
but it should look like these 5 lines instead:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
now make it look like that:

Code: Select all

        local random_number = math.random(1, 51)
        fDrawImage(cr, '/home/logansfury/Pictures/microsoft_jokes/' .. tostring(random_number) .. '.png', 162, 107, 324, 214)
        local dangler = io.popen('some bash command goes here')
        dangler:close()
    cairo_surface_destroy(cs)
    cairo_destroy(cr)
end
Partial success :)

It looks like a good starting point. What happened was:

- it played an mp3 (7.mp3)
- it then played a 2nd mp3 (22.mp3)
- after 2nd mp3 completed, it showed the image corresponding to 2nd mp3 played.

What I am looking for is

- display the .png image first
- immediately play corresponding mp3
- code to wait while mpg123 plays
- code to wait 2 seconds after mpg123 stops playing
- code to stop showing the .png

Here is the terminal output from the launch:

Code: Select all

conky: desktop window (2400010) is subwindow of root window (6cc)
conky: window type - normal
conky: drawing to created window (0x7000002)
conky: drawing to double buffer
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.3.2-1 (2012/03/25). Written and copyrights by Joe Drew,
now maintained by Nanakos Chrysostomos and others.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!

Directory: /home/logansfury/Music/eyegor
Playing MPEG stream from 7.mp3 ...
MPEG 2.0 layer III, 48 kbit/s, 24000 Hz mono
                                                                            
[0:07] Decoding of 7.mp3 finished.
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.3.2-1 (2012/03/25). Written and copyrights by Joe Drew,
now maintained by Nanakos Chrysostomos and others.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!

Directory: /home/logansfury/Music/eyegor
Playing MPEG stream from 22.mp3 ...
MPEG 2.0 layer III, 48 kbit/s, 24000 Hz mono
                                                                            
[0:06] Decoding of 22.mp3 finished.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
Post Reply

Return to “Compiz, Conky, Docks & Widgets”