Open file location [SOLVED]

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Open file location [SOLVED]

Post by JumpyVB »

Hello all fellow gambasers. I will start with an introduction. I have dualbooted windows and solus linux for 5 years. I never managed to install gambas on solus. But things have changed now. I just bougth a new pc and I am now trying to survive with linux mint only. Being familiar with vb2008express I feel mostly at home with gambas 3. I am recoding some of my most needed tools from windows to linux mint. Some questions do arise. I will start with a simple one:

How do I launch the filemanager nemo with a specific folder opened and a specific file in that folder preselected? And most importanly I want nemo to stay open when I close my gambas app.
Last edited by JumpyVB on Wednesday 22nd March 2023 2:32pm, edited 1 time in total.
User avatar
BruceSteers
Posts: 1522
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Open file location

Post by BruceSteers »

JumpyVB wrote: Tuesday 21st March 2023 7:14pm Hello all fellow gambasers. I will start with an introduction. I have dualbooted windows and solus linux for 5 years. I never managed to install gambas on solus. But things have changed now. I just bougth a new pc and I am now trying to survive with linux mint only. Being familiar with vb2008express I feel mostly at home with gambas 3. I am recoding some of my most needed tools from windows to linux mint. Some questions do arise. I will start with a simple one:

How do I launch the filemanager nemo with a specific folder opened and a specific file in that folder preselected? And most importanly I want nemo to stay open when I close my gambas app.
Opening the file,,, easy..


Exec ["nemo", sFilePath]



Keeping it open when killing the program that launched it... not so easy.

The above code should also keep nemo open when you close your program as long as you do not use Quit to hard kill.

the program will be closed but remain alive, hidden until the child processes are closed (nemo) then it exits

If your program uses Quit on exit then it will kill all child tasks so don't do that.
If at first you don't succeed , try doing something differently.
BruceS
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: Open file location

Post by JumpyVB »

Thank you. "Exec ["nemo", sFilePath]" will get me started. I will investigate further on how to set the child process free. Maybe its not a gambas thing but something I could do directly from a terminal aswel...Well what do you know. I found something promising, the $nohup command:

https://www.geeksforgeeks.org/nohup-com ... -examples/

But I cant test it rigth now. I will have get back to this. But thank you Bruce for getting me started.
User avatar
BruceSteers
Posts: 1522
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Open file location

Post by BruceSteers »

i do not think nohup is what you want.

I just tried this and it worked...

Public Sub OpenNemo(sSelectFile As String)

  Shell "nemo " & Shell(sSelectFile) & "&"

End


Placing a & at the end of the command seemed to free the child from the parent.
It was not possible to use & when using Exec so i used Shell instead.

Then the program opened Nemo and exited correctly while leaving nemo open.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1522
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Open file location

Post by BruceSteers »

Bruce wrote:Keeping it open when killing the program that launched it... not so easy.
Haha so i take that back.

It was pretty easy to just put an & sign at the end of the command ;)
If at first you don't succeed , try doing something differently.
BruceS
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: Open file location

Post by JumpyVB »

Thank you. I marked the thread as solved.
User avatar
BruceSteers
Posts: 1522
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Open file location

Post by BruceSteers »

JumpyVB wrote: Wednesday 22nd March 2023 2:31pm Thank you. I marked the thread as solved.
You're welcome.

There's other ways too.

DBus for example.
you can use dbus interface org.freedesktop.FileManager1
(you have to add gb.dbus component to the project for dbus functions)

Public Sub OpenLocation(sFile As String)

  DBus["session://org.freedesktop.FileManager1"]["/org/freedesktop/FileManager1", "org.freedesktop.FileManager1"].ShowItems([sFile], "MyProg")

End


using DBus will work with other file managers not just nemo.
seems iffy on cinnamon though.
for example both my MATE desktop and Cinnamon use Caja file manager , using the above command works okay on MATE opening caja but on cinnamon it says (error path is not a directory)

it works okay on kde plasma with thunar

Have fun :)
If at first you don't succeed , try doing something differently.
BruceS
JumpyVB
Posts: 75
Joined: Friday 11th September 2020 9:09am

Re: Open file location

Post by JumpyVB »

BruceSteers wrote: Wednesday 22nd March 2023 4:52pm There's other ways too. You can use dbus.
I've been meaning to learn DBus.

Just found your example here viewtopic.php?p=5727&hilit=singleinstance#p5727

I will try to implement it to a project of mine.

Thank you yeat again.
Post Reply