[Gambas-user] Get the default file manager

Bruce Steers bsteers4 at gmail.com
Sat Feb 17 17:08:04 CET 2024


On Sat, 17 Feb 2024 at 13:41, Gianluigi <gradobag at gradobag.it> wrote:

> Il 17/02/24 12:12, Gianluigi ha scritto:
> > I forgot,
> >
> > after the last fix you can also do something like this:
> >
> > Public Sub Main()
> >
> >   Dim sApp, s As String
> >
> >   Shell "xdg-mime query default inode/directory" To sApp  ' Get
> > .desktop file name of filemanager launcher.
> >   s = Scan(sApp, "*[.- ]*")[0]
> >   Print s
> >
> > End
> >
> > Regards
> > Gianluigi
>
> Hi Martin,
> I apologize in the suggestion there is an error, the space after the
> hyphen.
> For multiple strings you need curly brackets:
>
> Public Sub Main()
>
>    Dim sApp, s As String
>
>    Shell "xdg-mime query default inode/directory" To sApp  ' Get
> .desktop file name of filemanager launcher.
>    s = Scan(sApp, "*{.,-, }*")[0]
>    Print s
>
> End
>
> Regards
> Gianluigi
>


But that's risky.
It just checks the first word of the name of the launcher used to run the
file manager.
There is no guarantee the first word of the name of the .desktop file given
by xdg-mime is the command to launch the program.

I guess it depends on the needs. I guess.

To be most correct you should probably use DesktopFile.class as that
designed for .desktop files then you can access various bits of information
about it..

Dim sDFile As String
Shell "echo -n $(xdg-mime query default inode/directory)" To sDFile  '
Note: echo -n $() trick to omit trailing LF

Dim hDF As DesktopFile = New DesktopFile("/usr/share/applications" &/
sDFile)  ' get file as a DesktopFile object

Print hDF.ProgramName  ' the actual definitive program command
Print hDF.Exec  ' the complete command string used to launch it
Print hDF.Name ' just it's name (probably with capital letter)

But i now think none of this is your solution as i mentioned in the last
post about fixing your desktop configuration.

But it did raise a valid issue.

Why does DesktopMime return nothing for inode/directory ?

Well wishes
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20240217/cf8267e8/attachment.htm>


More information about the User mailing list