Please do not post a support request without first reading and following the advice in

[Solved] How to bind a shell command to a hotkey? (raspi2png)

  • @mitu said in How to bind a shell command to a hotkey? (raspi2png):

    If you don't quote your argument, spaces will surely be a problem. Anyway, here it is what I got so far.

    raspi2png --pngname "$(ps a | grep RetroPie/roms | awk -F "/" 'NR==1 { print $NF }' | sed 's/\.[^.]*$//g')"-$(date +%Y.%m.%d-%H.%M.%S).png

    This still won't get rid of the backslashes, e.g. creating Super\ Mario\ Bros.\ \(2P\ Hack\)-2019.02.23-18.10.44.png. But it does work with the .nes extension of this rom, thanks!

    raspi2png --pngname "$(ps a | grep RetroPie/roms | awk -F "/" 'NR==1 { print $NF }' | sed 's/\.[^.]*$//g')"-$(date +%y%m%d-%H%M%S).png

    Same here: Super\ Mario\ Bros.\ \(2P\ Hack\)-190223-181049.png

    echo -n "SCREENSHOT" | nc -u -w1 55355

    Works like a charm, thanks again for this alternative!

  • Global Moderator

    Yes, the dreaded \, forgot about them - I was testing with an emulator started. This can be fixed taking the sed command from your initial line:

    raspi2png --pngname "$(ps a | grep RetroPie/roms | awk -F "/" 'NR==1 { print $NF }' | sed 's/\.[^.]*$//g; s#\\##g')"-$(date +%Y.%m.%d-%H.%M.%S).png

    E.T.\ The\ Extra-Terrestrial\ \(1982\)\ \(Atari\)\ \(PAL\)\ [\!]-2019.02.23-17.20.15.png becomes E.T. The Extra-Terrestrial (1982) (Atari) (PAL) [!]-2019.02.23-17.25.43.png

  • @mitu To answer in German: Wunderbar! 😄

  • @mitu said in How to bind a shell command to a hotkey? (raspi2png):

    aspi2png --pngname "$(ps a | grep RetroPie/roms | awk -F "/" 'NR==1 { print $NF }' | sed 's/\.[^.]*$//g; s#\\##g')"-$(date +%Y.%m.%d-%H.%M.%S).png

    You might want to change that to raspi2png with an "r". 😉

    edit: Aaaand … I saw your post changing while I was waiting for this post to appear. 😆

  • Global Moderator

    @Clyde I already did :). Anyway, I think you should add a reference to your solution post to your 1st post, so people can find it without reading to the whole topic.
    Now the challenge is to find the equivalent of raspi2png for other platforms (Odroid, Pc).

  • @mitu Did you read my mind? I just did that. 😱 😄

    edit: Er … sorry, I didn't do that, but added a reference of your raspi2png solution to my first one. Adding the reference that you meant now. 😳

  • @mitu Done, along with "[Solved]" in the title and my How-To updated with your raspi2png line.

    I love communities like this for such constructive synergy. 😊

  • Love this thread, but I may need a smidgen more help to get this to work.

    I followed Clyde's guide to the letter, but after pressing the defined key, entering sudo systemctl status triggerhappy.server yields:

    Feb 23 19:01:19 retropie thd[2523]: Executing trigger action: raspi2png --pngname "/home/pi/$(ps a | grep RetroPie/roms | awk -F "/" 'NR==1 { print $NF }' | sed 's/.[^.]*$//g; s <---abruptly ends
    Feb 23 19:01:19 retropie thd[2523]: sh: 1: Syntax error: Unterminated quoted string

    Looks like it's cutting off the command line... No idea why. It looks fine in the config file. Actually, I just noticed that the line is being cut after EXACTLY 128 characters... So I wager I'm experiencing some character line limit that y'all are not.
    Edit: It turned out the character limit was a red herring and not the cause.

    FWIW, if I copy the same information from Step 4 into bash (removing KEY_SYSRQ 1) it works fine, and raspi2png takes the shot and the output file is named correctly. So the syntax as provided by Clyde (via Mitu) is definitely correct.

    I'm only having trouble w/triggerhappy truncating the line from the config file in triggers.d.

    Any advice?

  • Global Moderator

    @roslof If you post the contents of the /etc/triggerhappy/triggers.d/raspi2png.conf we may be able to spot any errors.

  • @mitu You bet, but it really is the same as step 4 above, and it definitely works at a bash prompt:

    KEY_SYSRQ 1 raspi2png --pngname "/home/pi/$(ps a | grep RetroPie/roms | awk -F "/" 'NR==1 { print $NF }' | sed 's/\.[^.]*$//g; s#\\##g')"-$(date +%Y.%m.%d-%H.%M.%S).png

    Syntax-wise, this is good. It just gets cropped during parsing after the 128th character.

    I did, however, figure out a work-around. I just created a separate script/.sh to run raspi2png w/all the parameters. Then I just called the script from raspi2png.conf ;-)

    My work-around:

    Newly added /etc/triggerhappy/triggers.d/ ensure executable perm flag is set

    raspi2png --pngname "/home/pi/$(ps a | grep RetroPie/roms | awk -F "/" 'NR==1 { print $NF }' | sed 's/\.[^.]*$//g; s#\\##g')"-$(date +%Y.%m.%d-%H.%M.%S).png

    Revised /etc/triggerhappy/triggers.d/raspi2png.conf

    KEY_SYSRQ 1 /etc/triggerhappy/triggers.d/

    Edit Note: Previously posted a line that used nohup, which was non-essential. For the curious, it was: KEY_SYSRQ 1 nohup /etc/triggerhappy/triggers.d/ 0<&- &>/dev/null &

    I have to say, the command-line arguments you and Clyde created are super-creative. I never would have imagined a screen capture with proper naming, and a solution for ANY emulator, including non-Retroarch. Great work, guys!

  • removed post based on insights from mitu

  • Global Moderator

    @roslof That's not necessary on Raspbian (and RetroPie) since the pi user is already a member of the video group and has access to /dev/vchiq. This kind of advice (make the /dev/whatever writable to anyone) it's just encouraging bad practice - don't do it, instead make sure your user is in the correct group.

  • @mitu Helpful. I'll edit the post. Unclear why I was in this state.

  • @roslof Thanks for reporting this and for the workaround. I'll admit that I didn't test the last version of the string (note to myself: always test things before putting them online, even slight alterations of existing things).

    It can't be the length (alone), though. I tested the command echo "...1.........2.........3..." and so on to test a string limit for command in the raspi2png.conf, but it worked well up to the 140 characters that I tested.

    This is the output of sudo systemctl status triggerhappy.service with the last version of @mitu's string:

    Feb 24 09:11:54 raspi thd[1458]: Executing trigger action: raspi2png --pngname "$(ps a | grep RetroPie/roms | awk -F "/" 'NR==1 { print $NF }' | sed 's/\.[^.]*$//g; s
    Feb 24 09:11:54 raspi thd[1458]: sh: 1: Syntax error: Unterminated quoted string

    Thanks for the compliments, I want to add @Lolonois who provided the very first part of the command string.

    @mitu My knowledge about bash fu is very limited. Do you have any idea what can cause this?

  • Global Moderator

    @roslof You shouldn't have :), now my reply doesn't make any sense.

  • @mitu @roslof Right, I missed the deleted post and now I'm wondering what it may have been about. 😉

  • Global Moderator

    @Clyde Hm, I bet it's because it interprets the # as a comment start. Try this

    raspi2png --pngname "/home/pi/$(ps a | grep RetroPie/roms | awk -F "/" 'NR==1 { print $NF }' | sed 's/\.[^.]*$//g; s/\\//g')"-$(date +%Y.%m.%d-%H.%M.%S).png

  • @Clyde sorry, man -- but it sounded like a sub-par solution to perms issues I was having. Since mitu advised not to follow the directions, I felt it best not to give that information to the public, in case they didn't get the warning.

  • Global Moderator

    @roslof It's ok to leave it - this way when someone googles for this advice will see that a reply with 'bad dog' has been added and think: "Hey, that's how you do it right".

  • @mitu That works! I'll update my solution with this and add a remark about @roslof's workaround in case someone wants to run a script instead of a single command. Thank you both!

    edit: Just when you posted your solution, I wanted to report that changing the length by removing the whitespaces before and after the pipes didn't change the point of cutting off the line. You were faster. 😉

    @roslof As @mitu said, it's better (and widely seen as more honest and polite) to leave it and maybe crossing it out and/or commenting below it that it has been wrong. Just a friendly advice. 😊

Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.