Native file selector for Deno
Hey guys, I am creating a Deno compile executable , and I want the user to be able to select a file from their system. (I only care about MacOS and Windows).
The only info I want to get the full path to the file the user is selecting (I don't think this can be done on the web cause of browser security reasons that spoof the full location with FakePath).
Is there a way to do this using Deno? Or some sort of 3rd party module or node js module? Thx!
7 Replies
Not sure if there is a simpler way to do it but you can just spawn a child process that opens a file selector and then return the result to the parent
Thats an elegant idea! Didn’t know that there was a CLI command for this , never thought of it
it depends on the OS (and the desktop environment if you count linux)
For example, you can use
zenity
with GNOMEThat does seem like a useful tool. Some googling found https://pymotw.com/2/EasyDialogs/ but that seems to be deprecated.
You might be able to just pipe some AppleScript into osascript on MacOS to prompt the user to select a file.
See: https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/PromptforaFileorFolder.html
And: https://support.apple.com/lt-lt/guide/terminal/trml1003/mac
thank you! Seems like this is the way! I'm going to make a tiny deno lib for this
Yeah I was just thinking that might be a fun lib to write. 🙂
BTW, since you'll be working with commands, if you haven't seen it yet, Dax is a much nicer interface for that than Deno.Command. I use it all the time.
https://jsr.io/@david/dax#executing-commands
I feel like Windows must have something similar to osascript? But I wouldn't know where to look off the top of my head. Maybe PowerShell commands?
If you publish a version of that lib, please ping me. Sounds useful!
Oh wow never heard of it before, I always been using the std 😭
Yeah I ended up using a powershell command
Fs!