phibr0 / obsidian-open-with

MIT License
35 stars 3 forks source link

Working directory Issues #4

Open sitepodmatt opened 2 years ago

sitepodmatt commented 2 years ago

Platform: Ubuntu 21.10 LTS 64bit Obsidian 0.12.19

The Obsidian application needs to launched with the working directory set to root '/' for this plugin to work correctly because it attempts to open external programs with a root relative path (i.e. no initial /). If you launch from your home directory it will attempt to open with with a root relative link and thus yield an invalid path e.g. /home/matt/home/matt/notes/interesting.md

Current workaround compatible with most DE: one can specify the working directory for the menu entry

➜  ~ more .local/share/applications/menulibre-notes.desktop 
[Desktop Entry]
Version=1.1
Type=Application
Name=Notes
Comment=obsidian notes
Icon=applications-other
Exec=/home/matt/Dropbox/tools/Obsidian
Path=/
Actions=
Categories=Office;
StartupNotify=true
➜  ~ 
lguenth commented 2 years ago

Hey @phibr0! I know this is an old issue but the reason for this behaviour is that you're normalizing the app.vault.adapter.basePath. The Zotero Integration plugin recently had the same issue where images were created in nested home folders and after some head scratching we found out that this is the culprit. If you drop the normalizePath, it should work again for all users.

getAbsolutePathOfFile(file) {
        //@ts-ignore
        const path = `${this.app.vault.adapter.basePath}/${file.path}`;
        if (obsidian.Platform.isDesktopApp && navigator.platform === "Win32") {
            return path.replace(/\//g, "\\");
        }
        return path;
    }
unbleaklessness commented 1 year ago

Made a pull request to fix this (#19).