Create macro to open files directly by editor

Hi people! I’m new with Komodo Edit and I’m trying to make a macro that opens files with relative paths, for example:

<script src="…/js/jquery.js"></script>

I’m trying with this macro:

var scimoz, selected;
scimoz = ko.views.manager.currentView.scimoz;
selected = scimoz.selText;

if(selected && selected.length > 0) {
// Open the file
ko.open.URI(selected);
}

But appears:

The file ‘\js\jquery.js’ does not exist. Do you want to create it?

How can I do this? Thanks!

ko.open.URI takes an URI, not a relative path. So you’d have to change your relative path into an URI.

Eg.

var file = ko.views.manager.currentView.koDoc.file;
var uri = ko.uriparse.pathToURI(file.dirName + "/" + selected);

That’s fairly pseudo and isnt exactly best practice (path concatenation), but should hopefully give you enough to proceed.

Thanks! It’s working now, now select the text isn’t necessary, you just click (focus) the file name and press “Ctrl + D”, all the text between double quotes is auto selected and the file is open. This works like a Dreamweaver resource… :smile:

Glad you got it working! Be sure to consider sharing your hard work with others :slight_smile:

http://komodoide.com/resources/submit-instructions/#pane-resources