RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

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

    Scheduled Pinned Locked Moved Help and Support
    hotkeyshortcutscreenshotraspi2png
    59 Posts 6 Posters 12.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • roslofR
      roslof @mitu
      last edited by roslof

      @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/run-raspi2png.sh 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/run-raspi2png.sh
      

      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/run-raspi2png.sh 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!

      roslofR ClydeC 2 Replies Last reply Reply Quote 2
      • roslofR
        roslof @roslof
        last edited by roslof

        removed post based on insights from mitu

        mituM 1 Reply Last reply Reply Quote 0
        • mituM
          mitu Global Moderator @roslof
          last edited by

          @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.

          roslofR 1 Reply Last reply Reply Quote 0
          • roslofR
            roslof @mitu
            last edited by

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

            mituM 1 Reply Last reply Reply Quote 0
            • ClydeC
              Clyde @roslof
              last edited by Clyde

              @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?

              mituM 1 Reply Last reply Reply Quote 0
              • mituM
                mitu Global Moderator @roslof
                last edited by

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

                ClydeC 1 Reply Last reply Reply Quote 0
                • ClydeC
                  Clyde @mitu
                  last edited by

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

                  roslofR 1 Reply Last reply Reply Quote 0
                  • mituM
                    mitu Global Moderator @Clyde
                    last edited by

                    @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
                    
                    ClydeC 1 Reply Last reply Reply Quote 0
                    • roslofR
                      roslof @Clyde
                      last edited by

                      @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.

                      mituM 1 Reply Last reply Reply Quote 0
                      • mituM
                        mitu Global Moderator @roslof
                        last edited by

                        @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".

                        1 Reply Last reply Reply Quote 0
                        • ClydeC
                          Clyde @mitu
                          last edited by Clyde

                          @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. 😊

                          roslofR 1 Reply Last reply Reply Quote 0
                          • mituM
                            mitu Global Moderator
                            last edited by

                            @roslof 's solution is also better when you just want to change something to the script command, since you don't need to re-start the thd service or edit the .conf file - any edits to the .sh file will take effect immediately.

                            ClydeC 1 Reply Last reply Reply Quote 0
                            • roslofR
                              roslof @Clyde
                              last edited by

                              @Clyde Thanks man. Still new here.

                              1 Reply Last reply Reply Quote 1
                              • ClydeC
                                Clyde @mitu
                                last edited by

                                @mitu The script version even relays the output of the script commands to triggerhappy's status output. I wasn't sure if it would do that. But I will keep it as optional for my solution post, because it adds more complexity, and one command should be enough for most people.

                                @roslof You're welcome! Besides, in some cases can deletion be advisable, like in this thread from me where @meleu's solution made my own completely obsolete (and wrong for many reasons). But I still added a remark about it original content. 😇

                                1 Reply Last reply Reply Quote 0
                                • ClydeC
                                  Clyde
                                  last edited by Clyde

                                  @roslof One question about your script variant: Is there a reason that you're using nohup and 0<&- &>/dev/null &? I'm asking out of curiosity and simplicity, because it seems to work as well if I just invoke the script by path and name, as do some triggerhappy guides I found online.

                                  And since I linked to your solution in mine, could you please add a remark that the script has to be made executable? (In my example for the owner "pi", or for "others" if the owner is root, since my solution configures triggerhappy to run as that user.)

                                  roslofR 1 Reply Last reply Reply Quote 0
                                  • roslofR
                                    roslof @Clyde
                                    last edited by roslof

                                    @Clyde As requested, I added a note in my previous post about setting the executable permission.

                                    Also, you're absolutely right about my use of nohup. It's not necessary for such a simple/quick script. nohup ensures the process doesn't stop until it's done. Overkill for the near-instant execution of the script. Again, my newbie-ness is shining through.

                                    Regardless -- Cool write-up on nohup, its uses, and why output needs to be considered for other, longer tasks:
                                    https://www.maketecheasier.com/nohup-and-uses/

                                    I revised my post with the simple path/script and included an edit note with my original nohup line for reference...
                                    Cheers

                                    ClydeC 1 Reply Last reply Reply Quote 1
                                    • ClydeC
                                      Clyde @roslof
                                      last edited by

                                      @roslof Perfect, thanks!

                                      1 Reply Last reply Reply Quote 0
                                      • cyperghostC
                                        cyperghost @Lolonois
                                        last edited by

                                        @Lolonois said in [Solved] How to bind a shell command to a hotkey? (raspi2png):

                                        @hermit triggerhappy is not related to retropie. AFAIK %ROM% or $ROM is not available from the environment. However, to get the rom file name you may start with

                                        basename `ps a | grep RetroPie/roms | head -1 | awk '{ print $NF }'`
                                        

                                        Without a physical keyboard attached the tool jslisten may be an option.

                                        This is definitly the master path for such purpose. Why it gets so less attention?
                                        Together with the jslisten tool we can call any script and manipulate filenames (because we aren't restricted to one liners) ;)

                                        Thx @Lolonois for this nice suggestion ;)

                                        @mitu @Clyde
                                        The triggerhappy solution is also nice but imho the joypad usecase is a real fine way to coop with.

                                        Btw: You can always use GPIO inputs to call commands

                                        ClydeC 1 Reply Last reply Reply Quote 0
                                        • ClydeC
                                          Clyde @cyperghost
                                          last edited by

                                          @cyperghost said in [Solved] How to bind a shell command to a hotkey? (raspi2png):

                                          Btw: You can always use GPIO inputs to call commands

                                          If you're not like me and prefer USB connections. ;) (because, I don't know, lazyness?)

                                          cyperghostC 1 Reply Last reply Reply Quote 1
                                          • cyperghostC
                                            cyperghost @Clyde
                                            last edited by cyperghost

                                            @Clyde Well ... I think it's not lazyness. I think with this Breadboard unit on Amazon.de there is no space for any excuse ;)
                                            So you develop your scripts and connections on this board and just take them over to your RetroPie ;)

                                            ClydeC 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            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.