You are not logged in.
Hello there,
I am running bspwm with sxhkd. Up to this point, I have been able to use another script (to utilise the middle mouse button for scrolling quickly and vertically on any application) in tandem with sxhkd. I have now tried to run another script, utilising parec, lame, and xclip (full details of script below). When I paste the script in line by line, it works. I also ran the command;
$ chmod +x $HOME/.config/sxhkd/record_audio_output.sh
$ ~/.config/sxhkd/record_audio_output.shAnd then;
$ ~/.config/sxhkd/record_audio_output.shIn a separate terminal window to kill the process. This method also worked.
Unfortunately, using the defined sxhkd shortcut (super + shift + a), does not work
The full script is below;
#!/bin/bash
if pgrep parec
then
# Stop recording audio
pkill parec
else
# Output device (the default one)
deviceMonitor="alsa_output.pci-0000_08_00.2.analog-stereo.monitor"
# 5-character random string
rand=$(cat /dev/urandom | tr -dc 'A-Z0-9' | fold -w 7 | head -n 1)
# Construct filename
filename="${HOME}/Downloads/out_${rand}.mp3"
# Record audio to the file
parec -d $deviceMonitor --volume=65536 | lame -r -V7 - $filename
# Copy the file to the clipboard
echo "file://${filename}" | xclip -i -sel c -t text/uri-list
fiAnd for reference, my sxhkdrc;
#
# custom hotkeys
#
# terminal emulator
super + Return
urxvt
# program launcher
super + @space
rofi -show drun
# screenshots
super + shift + s
flameshot gui
# audio clip
super + shift + a
~/.config/sxhkd/record_audio_output.sh
# make sxhkd reload its configuration files:
super + Escape
pkill -USR1 -x sxhkd
# autoscrolling
~button2
~/.config/sxhkd/autoscroll.sh
@button2
#
# bspwm hotkeys
#
# quit/restart bspwm
super + alt + {q,r}
bspc {quit,wm -r}
# close and kill
super + {_,shift + }w
bspc node -{c,k}
# alternate between the tiled and monocle layout
super + m
bspc desktop -l next
# send the newest marked node to the newest preselected node
super + y
bspc node newest.marked.local -n newest.!automatic.local
# swap the current node and the biggest window
super + g
bspc node -s biggest.window
#
# state/flags
#
# set the window state
super + {t,shift + t,s,f}
bspc node -t {tiled,pseudo_tiled,floating,fullscreen}
# set the node flags
super + ctrl + {m,x,y,z}
bspc node -g {marked,locked,sticky,private}
#
# focus/swap
#
# focus the node in the given direction
super + {_,shift + }{Left,Down,Up,Right}
bspc node -{f,s} {west,south,north,east}
# focus the node for the given path jump
super + {p,b,comma,period}
bspc node -f @{parent,brother,first,second}
# focus the next/previous window in the current desktop
super + {_,shift + }c
bspc node -f {next,prev}.local.!hidden.window
# focus the next/previous desktop in the current monitor
super + bracket{left,right}
bspc desktop -f {prev,next}.local
# focus the last node/desktop
super + {grave,Tab}
bspc {node,desktop} -f last
# focus the older or newer node in the focus history
super + {o,i}
bspc wm -h off; \
bspc node {older,newer} -f; \
bspc wm -h on
# focus or send to the given desktop
super + {_,shift +}{1,KP_End,KP_Down,KP_Next,KP_Left,KP_Begin,KP_Right,KP_Home,KP_Up,KP_Prior,KP_Insert}
bspc {desktop -f,node -d} '^{1,1,2,3,4,5,6,7,8,9,10}'
#
# preselect
#
# preselect the direction
super + ctrl + {h,j,k,l}
bspc node -p {west,south,north,east}
# preselect the ratio
super + ctrl + {1-9}
bspc node -o 0.{1-9}
# cancel the preselection for the focused node
super + ctrl + space
bspc node -p cancel
# cancel the preselection for the focused desktop
super + ctrl + shift + space
bspc query -N -d | xargs -I id -n 1 bspc node id -p cancel
#
# move/resize
#
# expand a window by moving one of its side outward
super + alt + {h,j,k,l}
bspc node -z {left -20 0,bottom 0 20,top 0 -20,right 20 0}
# contract a window by moving one of its side inward
super + alt + shift + {h,j,k,l}
bspc node -z {right -20 0,top 0 20,bottom 0 -20,left 20 0}
# move a floating window
super + {h,j,k,l}
bspc node -v {-20 0,0 20,0 -20,20 0}I am not sure quite what I am missing. I did double check that the shell script was executable, too, and it was.
Any help would be much appreciated. Thank you.
Changelog
I am using pipewire, and am now aware of the issue here, and in that case have explicitly defined the monitor in the script above. Running all of the aforementioned tests still yields nothing, unfortunately (except by pasting each line into a terminal, or executing the script directly in the terminal).
Last edited by 山猿 (2024-01-23 23:35:07)
Offline
Does it work if you call the full path? Perhaps sxhkd doesn't understand what "~" means.
Jin, Jîyan, Azadî
Offline
Does it work if you call the full path? Perhaps sxhkd doesn't understand what "~" means.
Hi there and thank you for your reply. My apologies; I forgot to add that I did test the full path as;
${HOME}/.config/sxhkd/record_audio_output.sh{HOME}/.config/sxhkd/record_audio_output.shAnd
/home/username/.config/sxhkd/record_audio_output.shBut unfortunately, none of these work.
What is puzzling is that a little beneath this command in the sxhkdrc file, under #autoscrolling, I do use ~ and scrolling does work as intended. My guess is there might be something wrong with the script, perhaps?
In that case, I also renamed the file as record_audio_output, keeping the file as an executable but this also did not work.
Offline
I would add this to the script just under the shebang:
set -xAnd use the keybind to run the script from a shell and record any output:
# audio clip
super + shift + a
sh -c '~/.config/sxhkd/record_audio_output.sh > ~/log.txt 2>&1'Then see if anything is printed in ~/log.txt after using the keybind a few times.
Which desktop is this? Could the shortcut be captured by the desktop instead of sxhkd?
Last edited by Head_on_a_Stick (2024-01-23 16:58:06)
Jin, Jîyan, Azadî
Offline
I would add this to the script just under the shebang:
set -xAnd use the keybind to run the script from a shell and record any output:
# audio clip super + shift + a sh -c '~/.config/sxhkd/record_audio_output.sh > ~/log.txt 2>&1'Then see if anything is printed in ~/log.txt after using the keybind a few times.
Which desktop is this? Could the shortcut be captured by the desktop instead of sxhkd?
Hi there,
Thanks again for your reply.
Following your advice, here is the output printed into log.txt after using the shortcut 3 times (pressing super + shift + a twice was counted as 1 time as the script is supposed to pkill parec after the second time it is called);
+ pgrep parec
+ deviceMonitor=alsa_output.pci-0000_08_00.2.analog-stereo.monitor
++ cat /dev/urandom
++ tr -dc A-Z0-9
++ fold -w 7
++ head -n 1The desktop is bspwm, so unfortunately, sxhkd is the only means by which a shortcut can be captured (sans any additional software).
Just to add, another interesting development; running btop shows the exact number of cat, fold, and tr processes running as were executed, and they are refusing to leave the cpu, so it is currently sitting at 92% usage.
Last edited by 山猿 (2024-01-23 17:24:12)
Offline
Looks like the command to extract $rand is stalling.
Try this instead:
rand=$(dd if=/dev/urandom bs=1 count=5)EDIT: no, doesn't work, sorry. Give me a minute...
Last edited by Head_on_a_Stick (2024-01-23 17:38:35)
Jin, Jîyan, Azadî
Offline
Offline
Dammit seth... ![]()
EDIT: for completeness sake, this should run without stalling:
rand=$(cat /proc/sys/kernel/random/uuid | head -c 5)Last edited by Head_on_a_Stick (2024-01-23 17:48:27)
Jin, Jîyan, Azadî
Offline
Dammit seth...
EDIT: for completeness sake, this should run without stalling:
rand=$(cat /proc/sys/kernel/random/uuid | head -c 5)
Thank you both for this, the above command works as expected. I was attempting to do something with mktemp, but I cannot seem to get an output. Something like;
rand=${mktemp -u | xsel -b -o | cut -c 9-}Though this throws an error;
bash: ${mktemp -u | xsel -b -o | cut -c 9-}: bad substitutionI am guessing this is because mktemp -u is considered unsafe? Or otherwise, is it because I am making a file, not generating a string, as such? I did try the other form of brackets too, but this led to the same error.
Finally, just out of curiosity, would you happen to know why cat /dev/urandom worked in the terminal but not in the script itself? Just so I can avoid that kind of thing in the future.
Thanks again very much for all your help.
Last edited by 山猿 (2024-01-23 18:04:13)
Offline
I'm not really sure why the /dev/urandom version didn't work, sorry.
But for mktemp(1), I think seth meant for you to use it to generate the filename directly, for example:
filename=$(mktemp "$HOME/Downloads/out_XXXXX.mp3")EDIT: and the "bad substitution" error is because you've use curly brackets instead of normal brackets.
Last edited by Head_on_a_Stick (2024-01-23 18:23:41)
Jin, Jîyan, Azadî
Offline
mktemp gets you a filename using a pattern, the entire xset | cut thing is nonsense and superflous.
mktemp "${HOME}/Downloads/out_XXXXXX.mp3"Edit: Dammit stickfigure... ![]()
Last edited by seth (2024-01-23 18:23:09)
Offline
I'm not really sure why the /dev/urandom version didn't work, sorry.
But for mktemp(1), I think seth meant for you to use it to generate the filename directly, for example:
filename=$(mktemp "$HOME/Downloads/out_XXXXX.mp3")EDIT: and the "bad substitution" error is because you've use curly brackets instead of normal brackets.
mktemp gets you a filename using a pattern, the entire xset | cut thing is nonsense and superflous.
mktemp "${HOME}/Downloads/out_XXXXXX.mp3"Edit: Dammit stickfigure...
Oh I see, my mistake; I thought mktemp would only output to /tmp. Thank you very much again, that's really helpful to know.
Offline
nb. that you probably still want to use
filename=$(mktemp -u "$HOME/Downloads/out_XXXXX.mp3") to not actually have mktemp create the file
urandom probably fails b/c shxkd closes stdin?
Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.
Offline
nb. that you probably still want to use
filename=$(mktemp -u "$HOME/Downloads/out_XXXXX.mp3")to not actually have mktemp create the file
urandom probably fails b/c shxkd closes stdin?Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.
Thank you for the note. I have amended the script accordingly. Thank you for the possible reason behind sxhkd failing, I will take a look into that a little more.
I have also updated the post to be marked as resolved.
Thank you again.
Offline