Sethu
Sethu4d ago

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
NeTT
NeTT4d ago
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
Sethu
SethuOP4d ago
Thats an elegant idea! Didn’t know that there was a CLI command for this , never thought of it
NeTT
NeTT4d ago
it depends on the OS (and the desktop environment if you count linux) For example, you can use zenity with GNOME
CodyC
CodyC4d ago
That 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
Sethu
SethuOP4d ago
thank you! Seems like this is the way! I'm going to make a tiny deno lib for this
CodyC
CodyC4d ago
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!
Sethu
SethuOP3d ago
Oh wow never heard of it before, I always been using the std 😭 Yeah I ended up using a powershell command Fs!

Did you find this page helpful?