You are not logged in.

#1 2025-02-04 14:50:59

set
Member
Registered: 2023-04-14
Posts: 15

script in dmenu

Well, I'm opening this thread because I haven't found anywhere how to solve it,

I want to use a normal script to open a song in the dmenu, the script and this

#!/bin/bash 
choice="$(find ~/Music -type f -name "*.flac" | sort -n | dmenu -i -l 10 -p "Play:")" 
[ -n "${choice}" ] && mpc --no-video "${choice}" &> /dev/null &

the problem is that I do not know where to put the script, and be able to run, because if I try to run it through the terminal, it can not be run in normal mode more only with root mode, and when I run the message, command not found

I don't know if I'm doing, something wrong in the script or the place it should run, I'm using i3, I tried to run it like this by shortcut

bindsym Control+A exec 'home/user/.local/script/music'

and nothing happened, if anyone can help me.

Last edited by set (2025-02-04 15:06:31)

Offline

#2 2025-02-04 15:51:06

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,225

Re: script in dmenu

I think there's a couple of examples in this old Dmenu Hacking thread. Post #2 might even be a better approach, assuming both dmenu and mpc still work today.

Offline

#3 2025-02-04 16:08:20

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,739
Website

Re: script in dmenu

mpc man page wrote:

If no command is given, the current status is printed

So add "play" after "mpc", as in the examples given in the thread linked by twelveeighty.

Last edited by Head_on_a_Stick (2025-02-04 16:08:39)


Para todos todo, para nosotros nada

Offline

#4 2025-02-04 16:46:24

set
Member
Registered: 2023-04-14
Posts: 15

Re: script in dmenu

I tried several ways, but there is no way to know if it will work or not, because it denied the execution of the script, and this first problem that I would like to solve, I tried until these the down, and even then it does not work.

#!/bin/bash

DMENU="dmenu -i -nb #000 -nf #7af -sb #000 -sf #fff -x 0 -y 32'"
MPD_HOST='localhost'
MPD_PORT='6600'
MUSIC_DIR=/my/music/dir/

function add_track
{
    ALBUM="$1"
    TRACK=$(echo -e "..\n$(mpc ls "$(grep "$ALBUM" /tmp/newalbum.$$ | awk -F / '{print $1}' | sort -f | uniq)/$ALBUM" | awk -F / '{print $4}')" | ${DMENU} -p "Find: " -l 30 -w 640)
    [ "${TRACK}" == ".." ] && add_album
    if [ "${TRACK}" != ".." ]
    then 
        mpc add "$(grep "${ALBUM}" /tmp/newalbum.$$ | awk -F / '{print $1}' |sort -f | uniq)/${ALBUM}/${TRACK}"
        MORE=$(echo -e "add more\nexit" | ${DMENU} -l 3 -w 100)
        [ "$MORE" == "add more" ] && add_track "${ALBUM}"    
    fi
    rm /tmp/newalbum.$$
    return
}

function add_album
{
    ALBUM=$(mpc listall | awk -F / '{print $2" - " $3}'| grep -v mp3 | sort -f | uniq | ${DMENU} -p "DmMpdC Find: " -l 30 -w 640 | sed -e 's#\ \-\ #\/#')
    echo "-${RANDOM}-"
    [ -z "$ALBUM" ] && return
    MODE=$(echo -e "add\nreplace\nopen" | ${DMENU} -l 4 -w 70)
    mpc listall | grep "$ALBUM" > /tmp/newalbum.$$
    [ $MODE == "replace" ] && mpc clear
    j=$(wc -l /tmp/newalbum.$$ | awk '{print $1}')
    J=$(( $j + 1 ))
    for ((i=1; i<J; i++))
    do
        [ $MODE == "add" -o $MODE == "replace" ] && mpc add "$( sed -n "${i}p" /tmp/newalbum.$$)" > /dev/null
    done
    [ $MODE == "open" ] && add_track "$ALBUM"
    [ $MODE == "replace" ] && mpc play 1
    rm /tmp/newalbum.$$
}

function select_track
{
    TRACK=$(mpc playlist | ${DMENU} -p "Find: " -l 30 -w 400 | cut -c 2- - | sed -r s/"\).*$"/""/)
    [ -z "$TRACK" ] && return
    MODE=$(echo -e "play\nremove" | ${DMENU} -l 2 -w 100)
    [ $MODE == "play" ] && mpc play "$TRACK"
    [ $MODE == "remove" ] &&  mpc del "$TRACK"
}

function toggle_random
{
    MRANDOM=$(mpc | grep random | awk '{print $5}')
    if [ "${MRANDOM}" == "off" ]
    then
        mpc random on
        notify-send -u low -t 1500 "MPD" "Shuffle switched on"
    else
        mpc random off
        notify-send -u low -t 1500 "MPD" "Shuffle switched off"
    fi
}

function mpd_status
{
    notify-send -u low -t 4000 "MPD" "<b>$(mpc --format '%artist% - %album% - %title%'| head -n 1)</b>
$(mpc | head -n 3 | tail -n 2)"
}

$1
#!/bin/bash 
query="$( echo "" | dmenu -p "Search: " <&- )" 
[ -n "${query}" ] && firefox https://www.google.com/search?q="${query}" &

I don't know if this is denial, because the script is wrong, or and other reason.

Offline

#5 2025-02-04 17:30:23

256
Member
Registered: 2023-12-17
Posts: 21

Re: script in dmenu

set wrote:
bindsym Control+A exec 'home/user/.local/script/music'

You're missing a '/' at the beginning of the path.


"Don't comment bad code - rewrite it." - The Elements of Programming Style (1978), Brian W. Kernighan & P. J. Plauger, p. 144.

Offline

Board footer

Powered by FluxBB