General :  K-Meleon Web Browser Forum
General discussion about K-Meleon 
Macro questions
Posted by: Borut
Date: May 26, 2019 04:52PM

Hi!

There are Macro topics in other parts of this forum, but I am not sure how much are they being read. So I decided to position this here, under "K-Meleon on Goanna", to be used for questions regarding macros. Sorry, if this is not appropriate.

My question:

I would be happy with some relatively easy way to get information out of the xml files (especially out of the browser\defaults\search.xml and Profiles\<xyz>\search.xml). Is there any macro library (or some other way which could be used in a macro) for xml parsing and extraction of data out of xml files?

I looked into http://kmeleonbrowser.org/wiki/MacroLanguage2 but did not find anything related to the xml format.

Thanks,
Borut

Options: ReplyQuote
Re: Macro questions
Posted by: JohnHell
Date: May 26, 2019 06:31PM

You don't need to complicate yourself. If you plan to edit your search engines, just go to the preferences panel > Browsing > Finding websites and from the Search Engines tab you will be able edit it.

Unless you are planning to deploy K-meleon, you don't need to modify the one at browser\defaults.

Those xml files don't have any special complication anyway. There is one main section and a sub-section auto closed for each search engine.
<engines>
    <engine caption="Description name of the engine" url="url for the query form url"/>
</engines>

But I recommend to edit it with the preferences panel.


I actually forgot to answer your question, but I'm not aware of any macro that parses or handles it beyond the tools offered by K-meleon preferences itself and Tools menu (shortcut to that panel).



Edited 2 time(s). Last edit at 05/26/2019 06:38PM by JohnHell.

Options: ReplyQuote
Re: Macro questions / xul etc
Posted by: siria
Date: May 27, 2019 11:34PM

Speaking of macros, another question for DEV experts, am struggling with such cross-probs since years:

How can macros be called by a chrome xul context-menu?

Am currently discovering exciting new possibilities for kmm-macros on chrome pages, specifically on aboutconfig, but cannot modify the context menu there with macro "setmenu". Only by injecting scripts, and at the moment have arrived here:

MenuItem.setAttribute("oncommand", "myfunction();");

That means I can already call a self-created JS function, but it would be so much handier to call a macro directly! I'll probably create also a normal entry in Tools or View menu etc, but with tons of macros those main menus are so cluttered already, and often hard to find. Having a new context menu entry ONLY on a specific chrome xul page which already comes with an own, tiny context menu, would be by far the easiest way to find it.

Or the other way around, perhaps macro-setmenu can modify xul-context menus too?? Just how? I mean menulines which will call "macros" too, not scripts (see above)

-----
@Borut: sorry no clue of xml or any tools either, and JS very little. When I needed similar functions in the past, have always just read the whole file as unstructured text (macro readfile(path)), and then fiddled with JS regex replacements for each line. Probably the worst possible way.



Edited 2 time(s). Last edit at 05/28/2019 11:34AM by siria.

Options: ReplyQuote
Re: Macro questions / xul etc
Posted by: JohnHell
Date: May 28, 2019 03:26PM

Maybe only adodupan or some anonymous user can answer this, but my guess is that the macro language is linked to the interface and I don't bet is possible to do that.

I'd wish that too, as would help to develop interactive configuration pages for macro inis and/or xmls or whatever, but I don't think it is possible sad smiley

Options: ReplyQuote
Re: Macro questions / xul etc
Posted by: siria
Date: May 28, 2019 04:31PM

Groping around in the dark, I wonder how those links on "about:home" know what to do exactly?
Can't find any clue, not in aboutHome.xhtml nor in aboutHome.js:
<li><a id="macros(Places_History)"> &abouthome.historyButton.label; </a></li>
<li><a id="sessions(OpenPrevious)"> &abouthome.lastSessionButton.label; </a></li>


Options: ReplyQuote
Re: Macro questions / xul etc
Posted by: anonymous
Date: May 28, 2019 07:17PM

@siria
KM compares id with registered commands.

Options: ReplyQuote
Re: Macro questions / xul etc
Posted by: Borut
Date: June 05, 2019 09:49AM

@JohnHell and siria:

Thanks for your suggestions. Everything is being appreciated, even when I do not answer immediately.

Another naive question, just to be sure:
The macro language does not provide for some kind of functions/function calls, does it? The only way of "calling" is like &somemacro?
The only way for data exchange, when "calling", is via variables?

Options: ReplyQuote
Re: Macro questions / xul etc
Posted by: JohnHell
Date: June 05, 2019 03:08PM

1. It depends in the context. From macros they must be called "&macroname;" but from menus.cfg or accel.cfg (and setmenu, setaccel macro functions) there is no need.

2. It was implemented in K-meleon 75.1. If roytam1 hasn't removed it, it should be available in Goanna versions. From 75.0 an below, you have to pass data through global variables.

Options: ReplyQuote
Re: Macro questions / xul etc / macro beginner tips
Posted by: siria
Date: June 05, 2019 05:27PM

(_HowTo_ macrolanguage Bugs beginner tips etc)

Quote
Borut
The macro language does not provide for some kind of functions/function calls, does it? The only way of "calling" is like &somemacro?
The only way for data exchange, when "calling", is via variables?

Sounds like you're seriously working with macros now, great! smiling smiley
Don't know which skills you already have, but just a few tips I wished someone had told clueless me in the first years:


Tips and HowTo for anyone interested in macro building:

Most errors are listed in the Error Console. It's found in the Tools menu, or enable the existing toolbar button (View > Toolbars > Javascript Console ), or open directly the URL "chrome://console2/content/console2.xul". By default Macro errors are OFF, click on button "ALL" to see them too.

Create this Bool pref in aboutconfig, by right-click:
kmeleon.plugins.macros.debug = true
After a restart the Error Console will complain not only about "KMM errors", but also tell you WHICH macro is broken and in which LINE!
Sadly the downside is a new debugging bug, introduced somewhere along the KM7X versions: after enabling this pref KM will show an error that the old "compat" macro is now broken, and it was automatically disabled. But as far as I know the purpose of this "compat.kmm" macro is only to convert extremely ancient macros written for KM1.1 or older! Really no prob But if you want to keep that macro and you're only occasionally writing macros, just toggle off that debug pref again and enable the compat-macro again, when finished.

Prob: another new debugging bug in error console, this one since KM-Goanna:
script errors now show only an extremely short javascripts extract, about 100 characters only, and the supposed "column" position is all wrong, for example 1145! But at least the tiny script extract does contain the complained error position in it somewhere.

Look into main.kmm to find tons of real expert macros as examples. Some of it's scripts are far too much "expert" for me, but in general have discovered a lot of interesting methods and insights in there.

Use an editor with syntax highlighting for macrolanguage, that helps **enourmously** to catch errors already while typing, for example to easily see which opened brackets are ending where exactly, etc. In the beginning I was so clueless and didn't even know such magical things like syntax highlighting exist! The prob is, I only have the very, very old inherited Scite version once customized by kko, where I've dabbled along the years to add some newer 7X macrocommands to the syntax, but overall customizing this app (or its ancient version) is far too complicated for me. Other macro editors (do a forum search) are far easier to customize, but I personally find the hightlighting syntax much better in old Scite, especially that it also shows if string quotes are not closed correctly or span aross several editor linebreaks.
Somewhere in the forum I've uploaded my slightly adjusted Scite version too, years ago, but over the years Dorian created yet more new commands.
And especially the "direct JS functions" since KM75.1 those now do allow for strings to span across several editor linebreaks, and of course old Scite still shows that as interrupted "...string...." errors.
But oh well, I can't use those 'modern' functions anyway if I want my macros to remain compatible with old KM1.x, so I still need those errors shown.

The big revolution is that since KM75.1 pure javascript functions can now be defined directly in kmm-files, which John mentioned above. That means no complicated wrapping of JS into KM-variables necessary anymore. I guess that makes writing and debugging 100x easier (if javascript is involved), and completely turns everything upside down debuggingwise.
Just not for myself, being stuck with KM1.6 on old OS, and of course want to use my macros too So have zero experience with that method. Please keep that in mind when reading my tips, they are mainly for old complicated way of handling JS in macro variables.

And there are also magical javascript formatting tools out there! Another miracle thing I discovered many years too late since I'm not a coder and no one told me those tricks :-( When knitting together endless javascript code by macro, like in my current aboutconfig_exporter macro again (still the old var-wrapping method), I'm always forced to merge the final code into a single JS line again before injecting it into *old* KM1.x-versions, and that giant pile becomes just one big code mess. For debugging, it helps to copy that final pure JS line into the clipboard before injecting it (setclipboard($_js)), that allows to investigate the pure JS.
That's where a fantastic NotepadPlus Plugin now comes to the rescue: JSTool with JSFormat. Out of that endless 1-liner it automatically creates pretty JS code with automatic linebreaks everywhere smiling smiley
But also great in general for everything dealing with JS, for bookmarklets, investigating scripts in webpage source codes etc.

In general, for big and complicated macros it helps to keep backups after every successful new step, in case the macro breaks later and then not knowing where to start searching. What exactly where those last edits again??

And to figure out which macro parts may cause any probs, little test alerts can be injected. To indicate if those specific parts are even running, and which value the variables have at that point.

When creating javascript snippets by macro variables, stuff like linebreaks must be escaped twice in it. That means \\n instead of \n, and \\\" instead of \", in file paths double backslashes \\ etc

Since KM1.6 there's also an extremely bad macro bug:
macro lines are not executed in order anymore, if any javascript code gets injected in between! sad smiley sad smiley
Especially its not possible anymore to toggle a pref by macro, inject a bit JS, and then toggle that pref back again by macro. The JS in between will work with the restored pref already! Somehow the following macro lines are now completely detached from any javascript that gets injected before them. That has caused me endless headaches, gray hair and wasted time over the years, and still all futile, no real solution sad smiley The only lousy workaround is to open some alert popup in the middle, that will keep the following macro lines at bay while the JS is executed. But horrible GUI of course. One day finally Dorian created a timeout command in macrolanguage, which would be a better workaround. Except that it only works with FULL seconds, far too long for that purpose! Especially if several such pause-breaks are needed.

Oh well, sorry for the novel. No clue if it helps you or anyone, of course not everybody is such a bloody coding beginner as I was at first. And still am when it comes to JS. Or to yet more gruelsome xpcom stuff for addons (which of course won't stop me when there's no other chance, but still an endless waste of struggling time!)



Edited 4 time(s). Last edit at 08/19/2019 03:26PM by siria.

Options: ReplyQuote
Re: Macro questions / xul etc / macro beginner tips
Posted by: Borut
Date: June 08, 2019 05:02PM

Hi JohnHell and siria! Many thanks again!

The hints about the functions, main.kmm (and the others too) as a source of inspiration and kmeleon.plugins.macros.debug=true proved invaluable (at this time and for me).

My next question:

I thought that I can do something like:
getpref(STRING,"kmeleon.general.sourceCommand");
but, as it seems, getpref() is not meant for that. Am I right?

Is there a way to get things from about:config?

Options: ReplyQuote
Re: Macro questions / xul etc / macro beginner tips
Posted by: siria
Date: June 08, 2019 05:39PM

Great! Good luck and have fun smiling smiley

Quote
Borut
I thought that I can do something like:
getpref(STRING,"kmeleon.general.sourceCommand");
but, as it seems, getpref() is not meant for that. Am I right?

Is there a way to get things from about:config?

Your getpref is completely right, should work perfectly.
It's macrolanguage, but perhaps you tried to use it as JS function?
Or one of the neighbor lines has a prob.

You probably have long since discovered this too:
http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage2
Not sure if the page exists in other languages too, like the FAQ page, but if so all others are extremely outdated (yet more as EN)

Speaking of aboutconfig, that's one of my current 2 macros in work ('almost' finished since weeks, technically works great long since, just as usual keep getting more ideas and then more possible probs, one step forward and 2 steps back, aargh...)

Options: ReplyQuote
Re: Macro questions / xul etc / macro beginner tips
Posted by: Borut
Date: June 08, 2019 09:38PM

Yes, sorry, I was really too quick with posting this last question. I had not one, but two errors in the neighborhood.

Your aboutconfig: I have installed it a few days ago! Nice to have it at a click distance.

Yes, I am aware of the page describing the macro language. For other interested people, here are a few really basic pages one should be aware of when starting with kmm (thanks also to JohnHell):
While reading about exec() once more, I spotted (should have seen it earlier) the link to:
http://kmeleonbrowser.org/forum/read.php?1,138352 (=How to launch external app in KM?) - Extremely useful, thanks for those examples!

Well, now I can start editing my macro from my macro, using my preferred editor (or notepad as a default). Time to go to sleep.

Options: ReplyQuote
Re: Macro questions / xul etc / macro beginner tips
Posted by: Borut
Date: June 10, 2019 04:07AM

The next two questions...

1. After a period of time of using alert() for debugging, I tried to use the logmsg() and was expecting to see the results in the error console (F12). Hm, no luck. Are there perhaps some known problems arround logmsg(), or error console?

2. What is the usual way to publish a new user macro, that could be useful for others too? A new thread under Extensions, with a link to a kmm-file in its first message? Or, is somewhere a kind of "repositiory" of macros?

Options: ReplyQuote
Re: Macro questions / xul etc / macro beginner tips
Posted by: JohnHell
Date: June 11, 2019 02:10AM

Quote
Borut
The next two questions...

1. After a period of time of using alert() for debugging, I tried to use the logmsg() and was expecting to see the results in the error console (F12). Hm, no luck. Are there perhaps some known problems arround logmsg(), or error console?

No clue. I never used till you reported here and it doesn't display anything, so, maybe is broken, or maybe is wrongly reported as available to 75.0, but it doesn't give errors anyway, so. I don't know. I ever used alerts, anyway.

Would be nice to see errors logs there, but when making macros, I just look at the error console if there is no response, that usually means I did some typo XD

Quote
Borut
2. What is the usual way to publish a new user macro, that could be useful for others too? A new thread under Extensions, with a link to a kmm-file in its first message? Or, is somewhere a kind of "repositiory" of macros?

To date, the best is to post it at the Extensions subforum. And, maybe here, but as stated there, that page is not used, the same as kmext.sourceforge.net, that is abandoned and I can't remember who was in charge.

So post at Extensions subforum.

Options: ReplyQuote
Re: Macro questions / xul etc / macro beginner tips
Posted by: Borut
Date: June 12, 2019 09:12PM

Quote
JohnHell
Quote
Borut
The next two questions...

1. After a period of time of using alert() for debugging, I tried to use the logmsg() and was expecting to see the results in the error console (F12). Hm, no luck. Are there perhaps some known problems arround logmsg(), or error console?

No clue. I never used till you reported here and it doesn't display anything, so, maybe is broken, or maybe is wrongly reported as available to 75.0, but it doesn't give errors anyway, so.

For KMM errors to be shown, the setting kmeleon.plugins.macros.debug should be set to true, as siria reported.

For logmsg() texts to be shown, one should apparently select JS (!), KMM and Chrome in the console. (I managed to find this with trial and error. The JS selection makes no sense for this, but it seems to be necessary.)

Options: ReplyQuote
Re: Macro questions / xul etc / macro beginner tips
Posted by: JohnHell
Date: June 13, 2019 01:40AM

Quote
Borut
For KMM errors to be shown, the setting kmeleon.plugins.macros.debug should be set to true, as siria reported.

I know, I'm constantly using it.

Quote
Borut
For logmsg() texts to be shown, one should apparently select JS (!), KMM and Chrome in the console. (I managed to find this with trial and error. The JS selection makes no sense for this, but it seems to be necessary.)

You made me to review it and it was the key combination for test macro file I made a clean up of keys a few weeks ago and I removed it so it didn't fire

Options: ReplyQuote
Re: Macro questions / xul etc
Posted by: adodupan
Date: August 05, 2019 09:03AM

Quote
siria
How can macros be called by a chrome xul context-menu?
Am currently discovering exciting new possibilities for kmm-macros on chrome pages, specifically on aboutconfig, but cannot modify the context menu there with macro "setmenu".

It is possible to add items to the context menu in the xul file. You can do this by using xul overlays.
When you do that, you can run the macro from a xul file (javascript) through the jsbridge plugin. Keep in mind this is possible in version 1.8, 74 and in roytam's latest versions, in version 75, 76 km crashes.
Here's a little test addon, a new menu item will appear in about:config, you can see inside how it works.
Make this macro first:
howtousejsbridge{
  alert(_("A simple example of how to use the JSBridge.SendMessage function."),_("Test"));
}
Then install
To change the text in the menu item you need to edit the howtousejsbridge.dtd file.
To change the macro you need to edit pref 'extensions.howtousejsbridge.macro'.

Regards



Edited 1 time(s). Last edit at 11/01/2020 07:44PM by JohnHell.


Options: ReplyQuote


K-Meleon forum is powered by Phorum.