Path to current *.komodotool file

Hello,
does somebody know please,
how to get absolute path to currently open *.komodotool file ?

Because…

ko.views.manager.currentView.koDoc.file.URI

returns e.g.:

 'macro2://33033/file.js'

This is how you would get the path to the currently open tool that you’re editing.

var profilePath = Services.koDirs.userDataDir;
var fileIO = require("ko/file");
var view = require("ko/views").current();
var pathToOpenTool = fileIO.join(profilePath,"tools",view.basename)

May I ask what you’re trying to do? If you’re planning on editing the tools on disk while Komodo is running you might get in trouble with Komodo running what’s in the Toolbox DB and not what you have on disk.

The toolbox only triggers updating the state of things when you’ve edited it in the Komodo UI, ie. through a tools property dialog or using the Edit… menu option on the tool.

  • Carey

Thanks for answer Careyh …

This part does not work for me, but it does not matter, other ways to get it.

	require("ko/views").current().basename

Anyway, it seems that you suggest join userDataDir path with relative path to komodotool.
Relative path between tools directory and komodotool file is still missing.

	'C:\Users\vilbur\AppData\Local\ActiveState\KomodoIDE\10.1\tools\HERE\ARE\SOME\DIRS\file.komodotool'

In other words I would like to turn magic number in ‘macro2://33033/file.js’ into path :wink:

Answer to your question:
I`m writing and testing scripts for extension as userscripts.
I would like to save userscript as *.js file for rebuilding of extension.
For smooth workflow…

What version of Komodo are you using? This should work and if it’s not working then other things may be broken/unsupported.

To clarify, you have userscripts that are implementing functionality of your extension. Once you know they are working you want to rename them to .js files? This won’t work since it’s not just JavaScript in the files. You’re going to have to extract the “value” field from the Userscripts.

There is no such file as macro2://33033/file.js. That is an internal protocal that we implement in Komodo for the toolbox. It takes the “value” field from a tool and injects it into a view so you can edit it. When it’s saved it’s saved to the toolbox database in the value field again.

Please confirm my guess at your use case and we can get you sorted out.

  • Carey

Komodo IDE 10.1.

I know how komodotool file looks like and how to save it as js file.

So, is there any way how to get path from database ?
It should be, since Komodo know where to save. :wink:

var toolbox = ko.toolbox2.getStandardToolbox();
var tool = toolbox.getChildByName("blah",true);
tool.path

That should do it.

You have hard time with my question :wink:

This will do it, but it finds komodotool by name.

It fails, if multiple tools with same name exists.

I really would like to get path of particular komodotool.

I answered your question but you haven’t answered any of mine.

Until you give me a use case I’ve got no more time for this.

No kidding. List your use case and restrictions and we can help you. Otherwise start playing in the Komodo console View > Tabs and Sidebars > Console

  • Carey

I would like to prevent misunderstanding, I really appreciate your attention.

I know all suggested ways.

I wrote my use case, but it is not necessary in this case, it is general question.

How to get absolute path to exact komodotool file.

All I need is equivalent of

ko.views.manager.currentView.koDoc.file.path

But for opened userscript or snippet.

I am interested in this question for years of playing with console. :wink:

And if you still interested about my use case…

I just wrote script which does on one click:

  1. Get opened extension project
    If not opened, get last extension project

  2. Loop opened files, save opened *.komodotools which belongs to project as *.js files

  3. Build and install extension

  4. Restart Komodo

… but with workaround for converting komodotools to js

I think what you’re looking for is

komodo.macro.path

This only works when in a userscript (which used to be named a “macro”, and are still called that in the backend).

Thanks to nathanr.

komodo.macro.path

It can be useful.
Although it must be placed in current macro.