Score:0

Finding a program running as AppImage

dz flag

In order to launch it from java with some command-line parameters, I'm trying to localize programmatically a certain application ran as AppImage. In my case it is the MuseScore application.

I installed it with the command ./MuseScore*.AppImage install.

I first tried from a terminal to localize that application using different options dpkg-query -L musescore and which musescore. I had no response.

In Windows, I can either search the registry or parse the result of a command-line command assoc ".myext".

Then, in Java, write use a

String program=null;
Process pr = Runtime.getRuntime().exec("cmd /c assoc \".myext\"");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(pr.getInputStream()))) {
    program=reader.readLine();
}

How could I do this in Ubuntu?

lvr123 avatar
dz flag
Sure. Installing and running this application are not the issue (`libfuse2` is installed and "install" has just created some subfolders in the user's home folder). The question: is *which command can use in a Termincal (e.g.) to retriece where this AppImage is located ?* Because my java application needs to call that AppImage with some other parameters. Actually I'm looking to the equivalent in Linux to Window's `assoc ".mscx"` or the equivalent of searching the Windows Registry for the key `"HKEY_CURRENT_USER\Software\Classes\MuseScore.mscz\shell\open\command"`.
lvr123 avatar
dz flag
Thanks. Solved.
Score:0
cn flag

./MuseScore*.AppImage install moves the appimage to ~/.local/bin.

A command named musescore is not created thus the which-command you used was useless in this case. dpkg will not give you any clue either because you didn't use dpkg to install it. The installation also created some symlinks to the appimage named mscore-portable and musescore-portable.

You can use the find-command to locate the appimage. I didn't need to do that, I simply read the output of the install-command.

To run the appimge from commandline you need to specify full path to the appimage or one of the symlinks if ~/.local/bin is not in your PATH.

Score:-1
us flag

If you need to know where the AppImage binary (or any file) is located, run the following command.

find / -name "*.AppImage" -exec ls -l {} \;

The command find will search root /, and then ls -l will display the path to the file(s). If the filename has changed, adjust accordingly.


As others have pointed out, using dpkg-query -L musescore does not yield any results because the binary was not installed using the package manager; thus, dpkg does not "know" its existence.

And using which musescore also does not yield results because the AppImage is not in a directory defined in the PATH, nor is the filename of the executable binary, i.e., the binary is MuseScore.AppImage and not musescore.

Score:-1
dz flag

One can achieve this in 3 steps:

  1. (Optional) Retrieve the mime-type of a file managed by the searched application

Command: xdg-mime query filetype path\to\a\file

Result: application/x-y-z

  1. Search for the application handling this mime-type:

Command: xdg-mime query default application/x-y-z

Result: someapplication.desktop

  1. Search for that desktop file and extract the exec path: Search the files in the folders listed in XDG_DATA_DIRS as well as /home/myuser/.local/share/applications/. If found, parse it as a regular Property file and search for the Exec property

See https://gist.github.com/lgvr123/cdeb8f432ddfdc0ae56ce23e71f1b177

  1. Alternatively, if (3) failed : Search for the application locally:

Command: which someapplication (Please note that ".desktop" has been removed from the result of step (2) )

Result: /home/myuser/.local/bin/someapplication or an empty string if the application is not presente locally.

mook765 avatar
cn flag
This may work or not work. It will only give you the correct result if the application you are looking for was set as default application for the mime-type.
lvr123 avatar
dz flag
Good observation. I combined both approaches in my java code. First this one. Then, if it has not returned the expected application, I'm searching the application in expected locations.
mook765 avatar
cn flag
Instead of using `which` it might be better to look in the `exec`-line of the desktop-file, this will tell you exactly where the executable is located.
lvr123 avatar
dz flag
For me it worked. So it remains my solution. Although I'll check your suggestions.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.