💾 Archived View for bbs.geminispace.org › u › skyjake › 11917 captured on 2024-06-16 at 19:40:32. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-05-26)
-=-=-=-=-=-=-
Re: "How to open files and URLs with the preferred application..."
Yeah, AFAIK there isn't a cross-platform solution for this, unless you're using SDL (2.0.14+) where you can find `SDL_OpenURL` that is very helpful.
In general, opening files can be done via file:// URLs, so you'll probably just need a way to open URLs in a default program.
In addition to SDL_OpenURL, as a fallback Lagrange tries:
Why urlopen.bat? It's been a while, but I think it was because on Windows Lagrange is built on the MSYS2 runtime, so it is a predominantly *nix like environment, and the most reliable way that I found to do the URL opening was to run a native Windows cmd.exe and run the `open` shell command inside that.
2023-11-21 · 7 months ago
🛰️ lufte [OP] · 2023-11-21 at 17:20:
Thanks for the tips guys, I guess I'll start with xdg-open and move from here. Sorry if I touched a nerve there clseibold ;)
😺 gemalaya · 2023-11-21 at 18:13:
Never tried this one but there's open-python:
https://pypi.org/project/open-python/
🛰️ lufte [OP] · 2023-11-21 at 22:30:
Taking notes here. The implementation from open-python looks simple enough too.
🌲 sloum · 2023-11-22 at 04:16:
While not perfect, you can usually detect the OS in use from an env var (again, not always relioable but pretty good) and then switch on the OS using xdg-open on linux, open on osx, etc. (providing a fallback as just downloading the file when a program is not available or there is not a handler for a filetype).
👻 mediocregopher [...] · 2023-11-22 at 07:19:
If a Linux system doesn't have xdg-open, is there some alternative URL opener it might have? I've only ever seen xdg-open...
👻 mediocregopher [...] · 2023-11-22 at 08:37:
@clseibold thank you for doing my research for me :) I'll remain contented with xdg-open then.
re: working in a terminal-only environment, I can't think one would.... what the behavior even be? Run a process as a background job in the current shell?
🌲 sloum · 2023-11-22 at 21:15:
@clseibold Yes, most languages will have some module for OS detection. You can check against `$OSTYPE`, which I believe should be available for pretty much every major system. Subprocessing out to `uname` can also be useful for this purpose. I can't remember which I did... my use case was in a makefile (for gnu make, since bsd make does not support if statements). So I think it makes sense in a makefile (again, targeting a non-bsd system) but may not have the same use case in a more full featured language/environment.
How to open files and URLs with the preferred application in multiple operating systems? Not really related to Gemini, but I need to implement a way in my Gemini client to open unsupported URLs and files on their proper apps, mostly on Linux but ideally in other systems as well. Fellows who have written their own clients, how did you do it?