Komodo SDK

I was want in my userscript open filedialog and store the filepath into variable. I use the topic from:

var filepath = require("ko/ui/filepath").create({filetype:"file"});
panel = require("ko/ui/panel").create();
panel.addRow(filepath);
panel.open();
// userselects a path
var name = filepath.value(); //outputs selected path.
console.log(name);

The dialog was open, but the path is not stored into variable.
Help me, please!

Hi @bigmdm,

This won’t work in this context. All that code has finished executing long before you ever hit the ... button to open the file selector dialog. Try dropping your code sample into the JS Console in Komodo: View menu > Tabs & Sidebar > Console.

You’ll need to add some sort of event handling so you can retrieve the value selected in the filepicker asynchronously. The most obvious use case would be in a button that you put in the panel as well which has a function for onClick that retrieves and does something with the variable selected.

// Without this option added to the panel it will disappear as soon as you click away from it
var panelAttrs ={noautohide: true}
var filepath = require("ko/ui/filepath").create({filetype:"file"});
var btn = require("ko/ui/button").create("print")
// Here's the call back that will do what you need
btn.onCommand(() => {console.log(filepath.value())})
//Because of the attribute added above, we need a way to manually close the panel otherwise it will stick around forever.
var closeBtn = require("ko/ui/button").create("close")
panel = require("ko/ui/panel").create(panelAttrs);
// Alternatively, you could have whatever code you wish to run run here before you close the panel
closeBtn.onCommand(() => panel.close());
//closeBtn.onCommand(() => {console.log(filepath.value());panel.close()});
panel.addRow(filepath);
panel.addRow(btn);
panel.addRow(closeBtn);
panel.open();
// userselects a path
var name = filepath.value(); //outputs selected path.
console.log(name);
  • Carey

Thank you! I solved this problem in a slightly different way. I poll the result every 500 milliseconds.
https://github.com/bigbigmdm/KOMODO-CSS-PERCENT-ENCODER/blob/main/BASE64.ktf