Skip to content

Find out the directory from where the appImage was ran #172

Closed

Description

@jviotti

Say I have my appImage in /opt/myapp.AppImage, but I open it using the terminal from say /home/jviotti/Desktop:

cd /home/jviotti/Desktop
/opt/myapp.AppImage

How can I get find /home/jviotti/Desktop, the place from where I ran the appImage from, from the app?

Activity

  1. probonopd commented on Jun 22, 2016

    @probonopd
    Member

    $APPIMAGE isn't doing it?

  2. jviotti commented on Jun 22, 2016

    @jviotti
    Author

    Hi @probonopd ,

    $APPIMAGE returns the path to the AppImage. dirname $APPIMAGE returns the directory containing the AppImage. I'm looking for the directory from where the AppImage was called, when the user did so from the command line.

  3. probonopd commented on Jun 23, 2016

    @probonopd
    Member

    CWD/PWD?

  4. jviotti commented on Jun 23, 2016

    @jviotti
    Author

    I've tried that already, but it returns the mount point of the appImage (/tmp/.mount-XXXXX). Maybe we can propagate the current working directory, or expose it as another env var?

  5. probonopd commented on Jun 23, 2016

    @probonopd
    Member

    Can you give some context of what you are trying to do? "." is not sufficient?

  6. jviotti commented on Jun 24, 2016

    @jviotti
    Author

    Etcher opens a file selector dialog for the user to select the image. We've seen that for GNU/Linux applications that are opened from the command line, the file dialogs open with the directory from where the command was ran as a default.

    Consider GIMP, for example. If I navigate to $HOME/Foo/Bar and call the gimp command from there, GIMP's dialogs will open on $HOME/Foo/Bar as a default.

    We're trying to mimic the exact same behaviour. If I call the appImage from the command line when my current working directory is $HOME/Foo/Bar, then the dialog should open there by default.

    This is proving to be a bit challenging since we have no way to get the current working directory before the appImage was called. Instead, once the appImage runs, the current working directory becomes the appImage mount-point.

  7. probonopd commented on Jun 24, 2016

    @probonopd
    Member

    Are you using the binary AppRun or do you have your own AppRun? I think (although I didn't check) that by using your own AppRun you should get at the original cwd.

  8. jviotti commented on Jun 24, 2016

    @jviotti
    Author

    I'm using the AppRun binary, but cwd doesn't seem to be inherited, but I might be running a too old version. I'll upgrade AppRun and AppImageAssistant and report back.

  9. probonopd commented on Jun 24, 2016

    @probonopd
    Member

    No, you need to use your own script as AppRun. A bash script should do.

  10. jviotti commented on Jun 24, 2016

    @jviotti
    Author

    Ah, I misread the comment, sorry. I see, I think I have everything I need, so I'll close this ticket and re-open in case I encounter any other issues with it.

    Thanks a lot!

  11. ericLemanissier commented on Jul 1, 2016

    @ericLemanissier

    @probonopd The same problem exists with the scribus appimage, and it is quite important because it is not able to handle properly relative file paths coming from the command line. You suggested to comment out the chdir calls in AppRun.c. If these chdir are not mandatory, why would any one keep them ? In other words, If I make a pull request to remove them from https://github.com/probonopd/AppImageKit/bloacb/master/AppRun.c would it be accepted ?

  12. probonopd commented on Jul 1, 2016

    @probonopd
    Member

    @ericLemanissier see #137 (comment)

    Some (many!) binaries have paths in /usr hardcoded, and packaging such binaries inside an AppImage requires to binary-patch /usr to ././ which means "here". This only works if AppRun changes the working directory to the usr/ directory inside the AppImage before running the application.

    If you are developing and compiling the payload application and its dependencies yourself, then you might not need this. But for the majority of existing software, you do.

    So to answer your question, such a PR would not be accepted. A PR that would restore relative paths to absolute paths might (as in the link above). Or a PR that simply builds two versions of AppRun, one with and one without the chdir.

  13. jviotti commented on Jul 7, 2016

    @jviotti
    Author

    @probonopd A bash AppRun works fine for us, but would you accept a pull request to expose a custom environment variable, like APPCWD (happy to discuss naming), with this value?

    The addition of an env var means that we don't have to comment out the chdir calls, but still have a way to retrieve this information from the application, and have this feature coming from upstream instead of having to write a custom AppRun.

    See #191

  14. probonopd commented on Jul 7, 2016

    @probonopd
    Member

    Thanks jvotti, let's call it $OWD with O for Original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions