phibr0 / obsidian-open-with

MIT License
35 stars 3 forks source link

Copy absolute Path of File to clipboard do not start with "/" #2

Closed LudwigWS closed 3 years ago

LudwigWS commented 3 years ago

Environment: macOS, Obsidian v0.12.12

Can't work well in macOS, I think it may be caused by a problem of getting file path. (Have Verified)

Clipboard result: Users/ludwigws/OneDrive/MyNote/202109010915.md

        getAbsolutePathOfFile(file) {
            //@ts-ignore
            const path = obsidian.normalizePath(`${this.app.vault.adapter.basePath}/${file.path}`);
           // debug: this.app.vault.adapter.basePath = "/Users/ludwigws/OneDrive/MyNote", file.path = "202109010933 Obsidian open with app.md"
          // path = ""Users/ludwigws/OneDrive/MyNote/202109010933 Obsidian open with app.md"

          // I fixed it temporarily by adding this
           if (!path.startsWith("/")) {
           path = "/" + path;
           }
            if (obsidian.Platform.isDesktopApp && navigator.platform === "Win32") {
                return path.replace(/\//g, "\\");
            }
            return path;
        }
LudwigWS commented 3 years ago

Sorry, I got the reason wrong. Whether it starts with "/" does not affect the result. The reason is that the plug-in is started with the open command under macOS, and the binary name itself cannot be filled in. This is a problem with my configuration.