Announcement

Collapse
No announcement yet.

Newbie kdialog question

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Newbie kdialog question

    I have a small script to transcode videos for a tablet in mythtv. It works except for the kdialog command. When I paste the command into a terminal it works fine, but not in the script. What am I doing wrong? I'm using Kubuntu 12.04.

    #!/bin/sh
    VIDEOIN=$1
    FILENAME=$2
    OUTDIR=$3

    # Now we'll convert the new temp file to mpg using avconv
    cp $VIDEOIN "$OUTDIR/$FILENAME.tmp"
    avconv -i "$OUTDIR/$FILENAME.tmp" -acodec libmp3lame -ac 2 -vcodec mpeg2video -q 8 -vf scale=-1:480 "$OUTDIR/$FILENAME.avi"

    # Now, we'll remove the temp file
    rm -f "$OUTDIR/$FILENAME.tmp"
    kdialog --title "Mythtv" --passivepopup "Transcode of recording for tablet complete" 10

    #2
    This could be an consequence of X11 DISPLAY not being set. When running from a konsole window, $DISPLAY is set -- typically to ":0". When running from cron or started outside of the KDE environment, $DISPLAY is probably not set.

    Comment


      #3
      To set the $DISPLAY variable either run the script with "env DISPLAY=:0 /path/to/script" or add "export DISPLAY=:0" to the script.
      Last edited by james147; Nov 07, 2012, 05:12 PM.

      Comment


        #4
        Originally posted by james147 View Post
        ...to the script the script.
        Stutter much, James?

        Please Read Me

        Comment


          #5
          Originally posted by oshunluvr View Post
          Stutter much, James?
          I really should reread my posts when I edit what I first wrote down but that would require me to have a brain.

          Comment


            #6
            Thanks for the replies. I'll try setting the $DISPLAY variable tomorrow when I have more time. I would never have thought of this on my own.

            Comment


              #7
              Thank you Andy and James, but neither "env DISPLAY=:0 /path/to/script" nor adding "export DISPLAY=:0" to the script worked. Right now I simply watch the system monitor to see when the cpu load drops - not a very elegant way of doing it, but it works.

              Comment


                #8
                Switch to a virtual terminal (alt+ctrl+F1, use F7 to get back to the GUI) and try running it there, see if it spits out any useful output.

                Comment


                  #9
                  James, I'm not sure how to do that. The script is designed to be invoked from mythbackend. Running it from a terminal, virtual or otherwise, it would not understand VIDEOIN or OUTDIR. I did try running the script using a real file name and kdialog worked as it's supposed to. I also checked mythbackend.log and it tells me that the script has failed, but no indication as to why. Since this is run from mythbackend could it be a permissions problem?

                  Comment


                    #10
                    Originally posted by whitepine View Post
                    James, I'm not sure how to do that. The script is designed to be invoked from mythbackend. Running it from a terminal, virtual or otherwise, it would not understand VIDEOIN or OUTDIR.
                    You can modify the script to only run the parts that matter (ie the kdialog part, this would make it quicker to test). Or you can supply the arguments to the script manually like you did during testing:
                    I did try running the script using a real file name and kdialog worked as it's supposed to.
                    (I assume thats what you did given this statement at least).

                    I also checked mythbackend.log and it tells me that the script has failed, but no indication as to why. Since this is run from mythbackend could it be a permissions problem?
                    Scripts return the exit status from the last command executed ie, kdialog in your case, which is failing for some unknown reason so the script is counted to have failed. Best way to debug it is to try running the script in a headless environment (ie from a tty display (aka virtual terminal) you can switch to one by pressing alt+ctrl+F1, and alt+ctrl+F7 to switch back to the gui).

                    If it runs as expected try running it form a headless environment as the user mythtv runs it as.

                    Comment


                      #11
                      Yes, it probably is a permissions problem.

                      I think the mythbackend runs as the "mythtv" user. In a start up script for the KDE environment, you should allow windows from another user to be displayed. The command is xhost and would go something like this:
                      xhost +si:localuser:mythtv-user

                      This allows the "mythtv-user" (or whatever the exact user name is) to create windows on your display.

                      Comment


                        #12
                        James, I ran a test script from terminal and got my kdialog popup, then I ran it from a TTY logged in as my username and received "Kdialog: cannot connect to X server", then I logged in as mythtv and ran the script and again received "Kdialog: cannot connect to X server".
                        I tried adding the xhost line and variations on it such as "xhost +local:" but no luck. I think I,m wasting every ones time with this since it's not very important, it just bothers me that I can't find a solution.

                        Comment


                          #13
                          Did you run it with the DISPLAY variable set? And you are not really wasting anyone's time, if people think it is a waste of time then they will not respond to the thread, since people are then they do not think this

                          Comment


                            #14
                            Here is the latest thing I tried with no success:

                            #!/bin/sh
                            export DISPLAY=:0
                            xhost +local:

                            VIDEOIN=$1
                            FILENAME=$2
                            OUTDIR=$3

                            # Now we'll convert the new temp file to mpg using avconv
                            cp $VIDEOIN "$OUTDIR/$FILENAME.tmp"
                            avconv -i "$OUTDIR/$FILENAME.tmp" -acodec libmp3lame -ac 2 -vcodec mpeg2video -q 8 -vf scale=-1:480 "$OUTDIR/$FILENAME.avi"

                            # Now, we'll remove the temp file
                            rm -f "$OUTDIR/$FILENAME.tmp"
                            kdialog --title "Mythtv" --passivepopup "Transcode of recording for tablet complete" 10
                            xhost -local:

                            Comment


                              #15
                              It works for me ^^

                              What I did was:

                              Modified the script to just contain:
                              Code:
                              #!/bin/sh
                              export DISPLAY=:0
                              kdialog --title "Mythtv" --msgbox "Transcode of recording for tablet complete"
                              (ie the important lines, I changed --pasviepopup to --msgbox so I didn't miss the notification but it works for both)

                              Switch to a virtual terminal and run the script as the normal user: the msgbox is displayed on the desktop with the given message

                              Run it as root: Fails with unable to connect to display :0

                              Run
                              Code:
                              xhost +si:localuser:root # replace root with your mythtv-user, I only used root as I don't have any other users
                              in a terminal as the normal user

                              Run the script as root on the virtual terminal: the msgbox is displayed on the desktop with the given message

                              To make this work automatically you need to add the xhost line to run when kde starts (Autostart in system settings)

                              Comment

                              Working...
                              X