B4J Question How to open Thunar filemanager on MX Linux

ThRuST

Well-Known Member
Licensed User
Longtime User
Hi! I'm trying to open the filemanager Thunar with a specied path on MX Linux from B4J code. This is what I use.

B4X:
fx.ShowExternalDocument(File.GetUri("/", ""))

which opens the default webbrowser with the root file structure.

Perhaps using shell is a better way that's why I consult you experts out there

but since I'm new to Linux I ask for a solution here.

My question is not locked to MX Linux, but also any other Linux versions will do.
 
Last edited:

Sandman

Expert
Licensed User
Longtime User
Open a terminal and try this:
B4X:
xdg-open /tmp

That should open the dir /tmp in your default file manager. If it works, switch strategy to run that shell command instead of using fx.ShowExternalDocument.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Sandman Thanks. is xdg the filemanager called Thunar or the terminal itself? Where's these usually located? Sorry but I'm totally green with Linux ?
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
No. xdg-open is a command that opens the preferred handler for the specified file. So if you were to do this...
B4X:
xdg-open myfile.txt
...your preferred text editor would open the file.

I don't know how to make this more clear really, but I'll give it a shot.

1. Open Terminal (can be named many different things, but mostly called just Terminal of some sort)
- if this doesn't work, you need to seek help in the MX Linux forum.

2. In the terminal type xdg-open /tmp and press enter. /tmp is a directory, so the default handler of directories will be instructed to open it. In your case it seems likely that Thunar is the default handler.
- if this doesn't work, and you're sure you typed everything correctly, then you probably don't have xdg-open installed, and none of this will work for you. Your adventure ends here.

3. If step 2 worked, change your B4J code to run xdg-open as a shell command, together with the path to the dir that you want to open. In your example in the first post you seem to want to open the root dir (which is a bit weird, but sure, why not). In that case the command would be xdg-open /.

Best of luck on your journey into Linux Land, it's a wild and very fun ride!
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Sandman Thanks for your in detail explanation. I'll try the shell way hopefully that will work. I knew about terminal but it was a new experience to locate those files since Linux doesn't use the same file extension standard such as PC does. As each Linux versions seems to have different file structure the root is just a starting point ?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Sandman Btw which Linux version are you running? Is xdg standard in the other Linux versions? I tried MX Linux since it seems to be the most popular, or one of those at least.
I'm creating an application that should open the filemanager with a custom path, hopefully on all Linux versions so I'll be busy with the vmWare emulator ??
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I knew about terminal
It's not really all that different from Windows cmd.

Linux doesn't use the same file extension standard such as PC does
Well, that's just not correct. A .txt file is a text file in Windows, Mac and Linux. And so on for all file extensions. Some operating systems will open the files in different apps though, and some won't be able to open them at all. (For instance: you won't be able to open a file from Adobe Premiere in Linux, because there's no app able to read their files (as far as I know)).

As each Linux versions seems to have different file structure the root is just a starting point
Correct, the root is the starting point. That's pretty much the definition of root. However, most Linuxes have very similar file systems, thanks to standardization projects many years back.

Btw which Linux version are you running?
Debian Stable since many years. It can be intimidating to install for a newbie, they don't make it overly clear how things work, but once you figure it out it's really great. And so very, very stable. Looking at my stats my machine was last restarted 217 days ago, so roughly this March. We'll see when I feel the need to restart it next time, I don't have any plans for it anytime soon.

Is xdg standard in the other Linux versions?
Yes, xdg is a big standard.

I tried MX Linux since it seems to be the most popular
I've never heard of it before you mentioning it. I would say that Ubuntu is the - by far - most popular distribution. That's what got me started with Linux. It's built upon Debian, and at some point I grew tired of a couple of things Ubuntu did, so I moved to Debian. Very happy with it, no plans to change.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Post one of yours as well?
That's not really my thing, but you seem to be easily amused so why not.



I should note that my desktop isn't very beginner friendly. I've cherrypicked most parts to suit me, and configured them to my liking. Also, I like things efficient and no-nonsense. So no graphical effects or anything like that.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Sandman What screen resolution is that anyway I'd like to see the file structure not just a black screen, so it sure was funny and I'm easily amused true haha ?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Sandman Where is xdg located in your system? Maybe it's enough to just call the command from shell without a custom path to the file?
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
What screen resolution is that anyway
3840x2160. https://www.b4x.com/android/forum/threads/when-did-this-happen.115622/post-722709

I'd like to see the file structure not just a black screen
I haven't changed the default file structure, because I'm not a masochist: https://wiki.debian.org/FilesystemHierarchyStandard

Where is xdg located in your system?
That's the wrong question, but sure:
B4X:
which xdg-open
/usr/bin/xdg-open

Maybe it's enough to just call the command from shell without a custom path to the file?
1. That's the right question
2. Be brave! Try it! You go, girl!
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Dear Mr. @Sandman , I have to consult you once again. Because I have tried your advice and non of them worked from shell.
I located xdg just like you said with which xdg-open which showed that the path is
/usr/bin/xdg-open

so I tried

B4X:
tstr = "/usr/bin/xdg-open /"

That didn't work.

Here's the code. Do you mind testing this on your Linux plz.


B4X:
                Try
                   
                    Dim tstr As String
                    tstr = "xdg-open /"
       
                    Dim shl As Shell
                    shl.InitializeDoNotHandleQuotes("shl", "Open", Array As String ("" & tstr))
           
                    shl.WorkingDirectory = tstr
                    shl.Run(300)
                                       
                Catch
                    Log(LastException)
                    xui.MsgboxAsync(LastException, "")
                End Try

So be a man and correct it
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I have tried your advice and non of them worked from shell
I don't know what that means. You say you have xdg-open installed, but it fails to work? Is that it? Did you manage to open a terminal and try what I wrote above?

Sorry, I don't have time to help you figure this out in detail, but this...
shl.InitializeDoNotHandleQuotes("shl", "Open", Array As String ("" & tstr))
...looks dead wrong to me. Should probably be something like...
B4X:
shl.InitializeDoNotHandleQuotes("shl", "xdg-open", Array As String ("/tmp"))
...to open the /tmp directory.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Ok, I needed a break anyway. This worked like a charm for me:
B4X:
Sub AppStart (Args() As String)
    Dim shl As Shell
    shl.InitializeDoNotHandleQuotes("shl", "xdg-open", Array As String ("/tmp"))
    shl.Run(-1)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…