Having default apps in xfce4 (def web browser, def media etc)


Super Roach

oh you can't put me on the spot like that!
Joined
Feb 11, 2011
Messages
114
Location
Australia
I'm trying to figure out how to have vlc play my media files when I am using the thunar filebrowser to navigate around. Usually I would navigate to a folder of music, try to double click on it and get a "default application picker" to select what should open it.


The problem is, I can't select VLC, and there is no other media player in the list it has. It has no recommended applications either.


Currently I have to open vlc then point to the files.


This gets annoying more for trying to click on "web browser", which has no link to chromium/firefox. Or trying to open a .zip file, even if I have file roller on the system.


Am I missing something obvious here to try and make my apps play nicer with the file browser?
 
the main problem is, that when launching a pnd, you don't start a program directly, but a script which starts the app. You can link a file type manually with the script and the right arguments to call the right app. But i think the script doesn't support handing over the arguments to the app which would allow e.g. vlc to load the file.


To get it working for vlc you could install it via opkg, which would install it correctly, but will fill up your nand disk space.
 
Here's one way to get vlc to play media files when you click on them in thunar:


create a script in your home directory called vlcwithfile.sh with these contents:



Code:
#!/bin/bash


launch=$(grep ^Exec /usr/share/applications/vlc-opie-vlc-26792#0.desktop)" -a \"$1\""


echo "${launch:5}" > /tmp/vlcwithfile


chmod +x /tmp/vlcwithfile

exec /tmp/vlcwithfile


make it executable with chmod +x. Then right-click on a media file, choose "open with other application" and choose "use a custom command" and type in /home/YOURNAME/vlcwithfile.sh.


It seems a bit over-complicated, and it assumes you've got the vlc pnd in apps or menu (not desktop), and it won't work (in principle) for other pnds, so there's likely to be a better solution.


EDIT: Lomaxx is correct - this doesn't work for files with spaces in them. :(
 
Last edited by a moderator:
@freamon: I think your script does not work with movies that got spaces in there filename. Even if you would use "$*" instead of "$1" then there probably will be problems, because "pnd_run.sh" interprets the filename as several parameters. I also tried it with quotes. I ran out of time while writing my version of a script and some explanation in order to be able to do it for other pnds. I'll probably post it tomorrow.
 
Last edited by a moderator:
That's why you don't put spaces in filenames on a *nix computer. Spaces count as seperators for parameter lists.
 
@klapse:


While this is somewhat true you should not rely on it. I find filenames with spaces and special characters annoying and don't create such filenames myself, but you must consider them. Especially when writing bash-scripts that modify data.
 
Here is my method of how i would try to solve this issue:


You can use "pnd_run.sh" (don't confuse this with "pnd_run" without ".sh") to build a small script that you assign in the same way that freamon specified his script. This is a bit of work. Let's take vlc as an example:


First of all, if you run "pnd_run.sh" without any argument in a terminal, then you get a quick overview about the parameters that "pnd_run.sh" takes.


Next I would start the pnd that contains the application. So in this case run vlc from the startmenu and leave it's window open in order to keep the pnd mounted. The plan is to get an idea where the pnd is mounted and which script is started.


The quickest way to find this out is to write the following in a terminal while the pnd is still running:



Code:
ps ax | grep pnd_run



The output will look something like this:





Code:
5053 ?	 Ss	 0:00 /bin/bash /usr/pandora/scripts/pnd_run.sh -p /media/trans8/pandora/menu//vlc.pnd -e scripts/vlc.sh -b vlc

5198 pts/2 S+	 0:00 grep pnd_run



We only care for the first line of the output and only for what comes after pnd_run.sh. The text behind "-e" shows which script is started and the text behind "-b" shows the mountpoint. So know we know that "scripts/vlc.sh" is started and that the mountpoint is "vlc"



With this knowledge and the fact that all pnds are being mounted in "/mnt/utmp/" you now can locate the startscript. It's always at "/mnt/utmp/<mountpoint>/<startscript_path>. So in this example "/mnt/utmp/vlc/scripts/vlc.sh". In order to get an idea what's going on in the script you take a look at it with either your favorite editor, or simply by using the "less"-command in a terminal:





Code:
less /mnt/utmp/vlc/scripts/vlc.sh



You don't have to understand everything of what's going on in this script. But you will see that some environmental-variables are being set ("export ...") and in the end vlc is being launched ("exec ./bin/vlc $*"). In general you will usually need such a startscript. So we will copy it over.



Now let's build our own script that runs a movie directly. I will be using the "pnd_run.sh"-command , the info about the start-script and the mountpoint and put it all together. Remember that you can type "pnd_run.sh" without anything else to get a quick help. The first line in the script is always needed. Also make sure to modify the paths to fit the location of your pnd. The script will:



- mount the pnd

- change the HOME-directory to the mountpoint so the application reads/writes it's configuration files there

- run a (in some cases modified) copy of the PNDs startscript

- unmount the pnd afterwards



Here's the script:





Code:
#!/bin/bash


#the following line mounts the pnd-without starting the application

/usr/pandora/scripts/pnd_run.sh -p /media/trans8/pandora/menu//vlc.pnd -b vlc -m


#change into the mountpoint and set the HOME-variable to that directory

cd /mnt/utmp/vlc

export HOME=.


#the following is a copy of the original start-script that we want to use

export PATH="/mnt/utmp/vlc/bin:${PATH:-"/usr/bin:/bin:/usr/local/bin"}"

export LD_LIBRARY_PATH="/mnt/utmp/vlc/lib:${LD_LIBRARY_PATH:-"/usr/lib:/lib"}"

export HOME="/mnt/utmp/vlc" XDG_CONFIG_HOME="/mnt/utmp/vlc"


if [ -d /mnt/utmp/vlc/share ];then

	 export XDG_DATA_DIRS=/mnt/utmp/vlc/share:$XDG_DATA_DIRS:/usr/share

fi

export SDL_AUDIODRIVER="alsa"

cd $HOME

[ -e "$HOME/scripts/pre_script.sh" ] && . $HOME/scripts/pre_script.sh

if [ -e "$HOME/scripts/post_script.sh" ];then

	 ./bin/vlc "$*"

	 . $HOME/scripts/post_script.sh

else

	 ./bin/vlc "$*"

fi

#end of start-script


#unmounting the pnd afterwards

/usr/pandora/scripts/pnd_run.sh -p /media/trans8/pandora/menu//vlc.pnd -b vlc -u



The only thing i modified in the section of the copied start-script was to remove the "exec" in front of of the line that starts vlc as it caused trouble when unmounting the pnd. Save the script using a name you prefer into your home-directory. I recommend to create a subfolder "scripts" for all future scripts you will write. I saved the script to "~/scripts/vlc-wrapper.sh".

Afterwards make the script executable just like freamon described:





Code:
chmod +x ~/scripts/vlc-wrapper.sh



In a terminal you can now test to pass a filename to the script. At this point you can also close the still running vlc that you left open before as mentioned in the beginning of the instructions. I used one with a rather ugly filename:





Code:
~/scripts/vlc-wrapper.sh /media/trans8/multimedia-data/movies/\[Demoscene\]\ Revision\ 2011\ -\ PC\ 05\ Flux\ by\ PandaCube\ \[PC\ Demo\ Competition\].mp4



The script should exit cleanly and executing "mount" manually afterwards should not show any signs of the mounted pnd anymore ("/mnt/utmp/vlc" in this case). So since this works nicely for me, I can now assign the script to movie-files. I'll copy freamons instruction on how to do that:



Right-click on a media file, choose "open with other application",choose "use a custom command" and type in "/home/lmx/scripts/vlc-wrapper.sh". Note: Using "~" instead of "/home/lmx" did not work for me. Also remember to replace "lmx" with your own username.



If this worked for you, then you can also try to modify the start-script to your needs. For example you can specify "-f" behind "./bin/vlc" to start vlc in fullscreen-mode:





Code:
./bin/vlc -f "$*"


I hope this works for you. With this information you should also be able to write similar wrapper-scripts for starting other pnds. Though you might have to make more advanced changes or will run into situations where the application does not take a filename as parameter at all. And by the way, you might want to use smplayer2 instead of vlc. Just try it all out.
 
Last edited by a moderator:
Awesome. I was messing around trying to fix my script for ages ...


Incidentally, the difference between "exec bin/vlc" and "./bin/vlc" is that 'exec' forks off and runs the application in a separate process, so the rest of the script would be run straight after vlc is launched, instead of when vlc is shut down (hence the un-mounting problem).
 
To be honest I didn't exactly remember the effect of "exec". Your appreciated explanation reminded me that I wanted to look it up. I took a look at "man bash" anyway and noticed that "exec" has a different effect than you explained:



Code:
exec [-cl] [-a name] [command [arguments]]

			  If  command is specified, it replaces the shell.  No new process

			  is created.  The arguments become the arguments to command.   If

			  the -l option is supplied, the shell places a dash at the begin‐

			  ning of the zeroth argument passed to  command.   This  is  what

			  login(1) does.  The -c option causes command to be executed with

			  an empty environment.  If -a is supplied, the shell passes  name

			  as the zeroth argument to the executed command.  If command can‐

			  not be executed for some reason, a non-interactive shell  exits,

			  unless  the  shell  option execfail is enabled, in which case it

			  returns failure.  An interactive shell returns  failure  if  the

			  file cannot be executed.  If command is not specified, any redi‐

			  rections take effect in the current shell, and the return status

			  is 0.  If there is a redirection error, the return status is 1.


Open a terminal and type "exec sleep 5s". You will notice that the terminal will be closed after 5 seconds and not kept open with "sleep 5s" running in the background. So in the above script the unmounting does not take place because the bash was replaced with the exec-command and thus the script was not being executed any further. I verfied this on my GentooPC: "exec sleep 5s ; beep" didn't let my computer beep.


Good to know that and still thanks. Because without you I wouldn't have looked it up. :)
 
My Pandora is in the post to ED now, so I cant test this & I may have just misunderstood the complexity involved here, however is it not possible to associate PND's to file types using either this old tweaks thread topic http://www.gp32x.de...ndpost&p=884458


or PND Utils on the repo here http://repo.openpand...l&app=PND_utils





or even the OVR editor & PND aware launcher http://boards.openpa...ation-launcher/


PND here http://www.mediafire...mjuz1gvj6zbth5y


Which will at the least, speed up finding the correct path and script for any given app, as it grabs the scripts path to the clipboard, or allow you to open a keyboard shortcut to it (which will always work despite xfce 4.8, if you apply the fix), when you click the 'set shortcut' button.


sgliee.png



Not sure if thats all irrelevant but I'll offer it up
 
Last edited by a moderator:
The Preferred Applications thing is only for Web Browser / Mail Reader / Terminal, unfortunately. pnd_utils looks very promising though (particulary the 'pnd_assoc' functionality).

I took a look at "man bash" anyway and noticed that "exec" has a different effect than you explained:

Well, that serves me right for guessing! I'd always thought that a script with



Code:
echo "A"

exec echo "B"

echo "C"

would print out ACB, but it doesn't of course - it just prints AB. ( ... I may some scripts to change ... eeek. )
 
@Mario: Thanks for the helpful links. While writing the above instructions I vaguely remembered that I somewhere read a much faster way of doing this. Now I know in which context it was (browser/mailreader/terminal). Beside the fact that I didn't manage to make a similar pnd_run-command work when trying to assign vlc as default movie-player (freamon already mentioned that it doesn't work), writing your own script still might have some advantage in this or that situation. Sometimes you might modify the starting-behaviour of a pnd.


I'll take a look at the other tools, which look interesting.
 
Last edited by a moderator:
This hooked me up. After thinking about it, I didn't see a reason why it should work for setting the default browser/mailreader/terminal but not for setting something like the movieplayer. I tried around and alas I do not manage to pass an URL to the default browser (I tried firefox) by using a similar line as used in the thread linked above. Either something change in the behavior of pnd_run or it doesn't work with the firefox.pnd or something else.


Will try some more later.
 
Last edited by a moderator:
The end result may be useful in a wiki latter on, as it was the first thing I ran into on getting my op - clicking on the "web browser" icon. Then trying to launch a media file.
 
Back
Top