I have been struggling with this too.
spawn_with_shell is not the solution that makes it work for me.
The screen flickers when I press the according hotkey, so that's configured correctly and when I press Win+r (run) and type path/to/screenshot.sh, that also works.
This is the script following the shebang
scrot -s '%Y-%m-%d_$wx$h_scrot.png' -e 'mv $f /home/sam/Pictures/Screenshots'
This are the things I've tried:
screenshot = "/home/sam/run/screenshot.sh"
awful.spawn.with_shell(screenshot)
What does work is executing the bash scripts with the terminal:
These are my variable definitions at the top of the page
screenshot = "/home/sam/run/screenshot.sh"
screenshot_cmd = terminal .. " -e " .. screenshot
And then way more down the file, I have these (both working)
awful.key({ modkey , }, "#107", function () awful.spawn.with_shell(screenshot_cmd) end,
{description = "take screenshot", group = "launcher"}),
awful.key({ modkey , "Shift" }, "p", function () awful.spawn(screenshot_cmd) end,
{description = "take screenshot", group = "launcher"}),
Unfortunately, the latter also opens a terminal window, which is not a desirabe behaviour
(But at least, something is working