General :  K-Meleon Web Browser Forum
General discussion about K-Meleon 
How to invoke context-menu items programmatically
Posted by: Zvonko
Date: June 25, 2018 09:48AM

Hi!

In the context menu of page displayed in KM there are menu items like 'Page Properties' or–if the page has a frame–'Frame'; under 'Frame' there is the item 'Save Frame As...'.

The context menu and such menu items can be invoked manually, via mouse clicks and/or shortcut letters.

I would like to do it programmatically (and in an invisible way).

How this could be implemented? Probably by a macro.

A macro, which would be triggered by a hotkey, and which would do–that is my target–'Save as Frame' silently in background, in a default folder under a default name.


Unfortunately I have no knowledge how to write a KM macro... Could someone here help me?



Edited 4 time(s). Last edit at 06/25/2018 10:30AM by Zvonko.

Options: ReplyQuote
Re: How to invoke context-menu items programmatically
Posted by: hermes
Date: June 25, 2018 12:41PM

@Zvonko

Did I understand correctly, that You need to automatically (better without any interface) open a certain page (or pages, perhaps a list on text file) in it to find a frame (or frames) and save this frame to hard drive in a folder of your choice?

All right? If so, give an example of such a page. And more rigidly define what I listed above. Because everything can be made easier. Can just write a program with specified functionality.

At the same time, let me clarify that the page can be saved in many ways (from a full copy of the text content to a recursive correction of links and embedding or saving images). And it's not the same thing. Maybe need to have only text or only images, etc.

Options: ReplyQuote
Re: How to invoke context-menu items programmatically
Posted by: Zvonko
Date: June 25, 2018 01:13PM

@hermes: Thank you for your answering!

No, no page should be opened by the macro etc. It is assumed that the page is already opened, i.e. the macro simply should do with the currently displayed page what I am able to do manually by invoking the context menu, then selecting Frame > Save Frame As, then specifying a file name and pressing Enter.

But
- this should be triggered by a hotkey, e.g. Ctrl+Shift+Alt+0,
- the process should be invisible (in the background), and
- the frame should be stored e.g. in C:\Test\Frame.txt (overwritting old file if existing).

Options: ReplyQuote
Re: How to invoke context-menu items programmatically
Posted by: siria
Date: June 25, 2018 05:10PM

Still wondering, because I keep reading "I wanna silently spy on another user of KM".
What do you really want?

Quote
Zvonko
Hi!
A strange question: Is the webpage currently displayed in KM saved somewhere on the computer (in a manner that it could be read from another program at this time)?

EDITED:
Or is there a plugin which could enable saving the text from each displayed webpage in regular time intervals?


Options: ReplyQuote
Re: How to invoke context-menu items programmatically
Posted by: hermes
Date: June 25, 2018 05:24PM

This method is inefficient for tracking work of another user.

I figured you needed a batch processing of pages to save some material (for example, frames).

However, if you just want someone to follow, there are other methods and technologies sharpened for this, but I do not consider it necessary to describe this within the framework of this forum.

siria is right, describe directly what you want if it does not violate rules of morality.

If all what you need is only save frame on disk, you must take into account that frame can be more than only one. Example page was requested for a certain reason. If we consider universal case, it will be more difficult with number of frames = X and a pre-known structure, which is easier.



Edited 5 time(s). Last edit at 06/25/2018 05:41PM by hermes.

Options: ReplyQuote
Re: How to invoke context-menu items programmatically
Posted by: Zvonko
Date: June 25, 2018 06:45PM

Waw, waw, waw! Spy on another user...tracking work of another user...to follow someone...if it does not violate rules of morality...??? Am I in the wrong movie or have you seen too many movies??? Again a case where I suffer a total shipwreck with a simple technical question... I guess I have to worry about this experience, something has to be wrong with me!

My friend is a doc with a small practice. He uses a Practice Management SW developed by me. The SW provides the full required local documentation of all medical activities. A component of this SW is to compose, save and print prescriptions for the patients. No problem until now.

But now a new system has been introduced from the clear sky: All prescriptions must be registered in a central national medical system. This means that a site must be visited in a browser. The site uses a frame, which content changes from page to page. The prescriptions must be selected from a list and finally sent to the site to be registered centrally.

Unfortunately the consequence of this new system is that all prescriptions are to be made twice: first on the site of central medical system (in a browser), second in the SW used for the local documentation.

My idea was to track the activity inside the browser by regularly saving the frame content into a text file, to extract the prescription data from such a text file, and to import these data into the local SW. Another solution is not in sight. To buy a completely new SW which interacts directly with the server of the central medical system would be extremely expensive, the small practice can not afford that.

So I came to the crazy idea to post one or two simple technical questions in this forum... With the result...–see above.

No, hermes, there is only one frame.

Options: ReplyQuote
Re: How to invoke context-menu items programmatically
Posted by: hermes
Date: June 25, 2018 07:04PM

OK. Now more clear. By the way, I wrote PM, but I warn you that service is unstable and notifications do not come indication of messages.

If you were to save everything on page and in a frame to a text file, would that suit you? What encoding do you need? Do you need config to specify locations of file? Do you want a solution for KM or for any browser? Save by key, timer or something?



Edited 1 time(s). Last edit at 06/25/2018 07:05PM by hermes.

Options: ReplyQuote
Re: How to invoke context-menu items programmatically
Posted by: Zvonko
Date: June 25, 2018 08:31PM

Waw, what a relief. In another forum today one has assumed, I plan "some kind of malware". It must have something to do with my personal way of questioning ...

What I need is limited to my given description. There should be a hotkey (e.g. Ctrl+Shift+Alt+0) which triggers the macro, and the macro simply should do Save Frame As, to a default path and file (e.g. C:\Test\Frame.txt, overwritting). Encoding can be simply ANSI. Finito. Only for KM, config would be nice, but not really required, no timer...



Edited 1 time(s). Last edit at 06/25/2018 08:32PM by Zvonko.

Options: ReplyQuote
Re: How to invoke context-menu items programmatically
Posted by: siria
Date: June 25, 2018 08:39PM

Quote
Zvonko
So I came to the crazy idea to post one or two simple technical questions in this forum... With the result...–see above.

You shouldn't be surprised in the current times, when every step and click someone does is tracked and phoned home and resistance is futile, if people ask for more details about repeated requests to save something automatically and silently in background.

Anyway, your prob sounds solvable in KM, especially with Hermes around (has programming knowledge) but more details are needed. For example am wondering: is there perhaps some sort of final confirmation page? Which perhaps repeats again the data you need? That would be handy, if such a confirm page has a unique URL, it could be triggered automatically "OnLoad" to "save file on disk" (or saving parts of it after some JS tweaks). Otherwise a shortcut or button would have to be triggered manually.

For the moment just CTRL+S perhaps?
That runs File > Save Page As...
and suggests the last used location.
A new tiny macro can very easily check if the current URL matches a given one and then change the pref for that last used path, perhaps change the current page title too, before calling File/SaveAs
And macros can call exe's or bat's too if needed, to trigger the next tool to take over.



Edited 2 time(s). Last edit at 06/25/2018 08:49PM by siria.

Options: ReplyQuote
Re: How to invoke context-menu items programmatically
Posted by: Zvonko
Date: June 25, 2018 08:51PM

Thank you, siria, for your friendly words.

No, no more details of use can be provided, there is nothing going above my given description. The whole process happens under the same URL, only the content of the frame changes. When I have the macro, I can trigger it by my SW according to my requirements and extract relevant data from each saved frame content, that is not difficult. The macro only should do Save Frame As, that's all.



Edited 2 time(s). Last edit at 06/25/2018 08:53PM by Zvonko.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: siria
Date: June 25, 2018 09:34PM

Couldn't resist, find attached a first draft, just a simply tiny macro :cool:
Guess you can customize little things yourself as needed.
There sure are more improvements possible, but for the moment should do.
Description is inside.
(PS: haven't tested, hope it works, LOL)

(PS: updated to version5)

Be aware, this only works if a $FrameURL really exists!
Am not quite sure from your description if you don't mean just a normal page and URL? In that case FrameURL is empty.
Alternatively you can compare the normal $URL of the whole page



Edited 4 time(s). Last edit at 06/26/2018 05:50AM by siria.

Attachments: SaveFixFolder.kmm (1.5 KB)  
Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: siria
Date: June 25, 2018 10:10PM

Quote
Zvonko
The macro only should do Save Frame As, that's all.

Actually for a simple shortcut this is already enough:
Edit > Configuration > Accelerators
Add your chosen key combination and command:
CTRL xx xx= ID_FILE_SAVE_FRAME_AS

The effect of the macro attached above is just to create a double-function for well known "CTRL S", to avoid the need to remember yet another new shortcut smiling smiley
And while at it, the macro checks if the saving path is still the same, just in case another webpage was in the meantime saved in another location.

Am still wondering about possible automatic triggers, how to catch that point and therefore eliminate the risk to forget the saving completely. But if the URL remains the same all the time it gets a bit difficult... perhaps with a timer function AFTER the loaded page had a specific URL or something...

PS: macro above now version-4. Have it rewritten to compare the complete URL, not compare only the beginning



Edited 1 time(s). Last edit at 06/25/2018 10:21PM by siria.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: hermes
Date: June 26, 2018 03:53AM

@Zvonko

Made as understood. This Kit allows you to save a page with frames (taking into account changes made to them). The page is not specially rewritten, You are parsing a page (as I understand it) and You can delete it when the page is no longer needed.
...
You will get an error if you continue to save when the page has not been deleted.
By default saves in C:\TEMP. Path can be overridden in a macro. But be careful: the edit must be correct, path occurs more than once and in some cases has additional \\, and in others - no. It is much easier and more convenient to create a TEMP folder in root of system disk. Each line of the macro has its own meaning and there is no extra. Part of work is performed by a separate binary module (because the desired functionality was not available in browser macro system).
The default key combination [ ALT ] + [ i ]. Operation tested on XP / 2k3 / 7.

For details and demonstrations recorded short video:
(direct link) https://getfile.dokpub.com/yandex/get/https://yadi.sk/d/R2TgYBMF3YQBtW (~299 Kcool smiley

Complete kit
(direct link) https://getfile.dokpub.com/yandex/get/https://yadi.sk/d/hl4i2PeU3YQBuN (~12 Kcool smiley

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: Zvonko
Date: June 26, 2018 06:11AM

@siria

I'am overwhelmed!

To test your macro at home (where I can not access the site directly, this is only possible in the practice where a special access box is installed) with pages saved from the site, I reduced your code to this:

$_SaveFixFolder_path = "C:\\Test\\" ;

SaveFixFolder_SaveFrameAs{
setpref(STRING,"kmeleon.download.saveDir",$_SaveFixFolder_path);
setpref(INT,"kmeleon.download.saveType",1);
id(ID_FILE_SAVE_FRAME_AS);
}

_SaveFixFolder_setAccel{
setaccel("CTRL 0","macros(SaveFixFolder_SaveFrameAs)");
}

$OnStartup=$OnStartup."_SaveFixFolder_setAccel;";


I am able to understand what the macro does. Is this way–invoking the menu item with the dialog–the only possible way? Does the KM macro language provide access only to menu items, not to the real functions doing the job?

Anyway, there is a dialog box, which in my setting shouldn't appear. My SW should use a timer to save data in intervals of 1 s or so, and the normal working on the site shouldn't be hindered by this. For my tests I already use a temporary workaround based on sending keys to the browser (RButton for context menu, f for Frame, s for Save Frame As, then the key sequence of my default file including full path [this works!], and finally Enter), which reduces to some degree the "visibility" of the desired "backgroud" saving operations; but this is not a solution, of course.

So on this level there is no solution without the dialog?



Edited 2 time(s). Last edit at 06/26/2018 06:14AM by Zvonko.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: Zvonko
Date: June 26, 2018 06:30AM

@hermes

I'am overwhelmed! Unfortunatelly in a double sense: not only by your generosity to do such a work for me, but also by the complexity of your work. I have to find an orientation first...

My expectation was that the macro language allows to call something like a "Save Frame As" function and to pass the desired arguments to it, and the job is done. That seems to have been an illusion. As already asked in my post for siria, the macro language seems to provide access only to menu items. Is this really so?

Is this the reason for your complex solution? What does the "binary module" do?



Edited 2 time(s). Last edit at 06/26/2018 06:46AM by Zvonko.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: siria
Date: June 26, 2018 06:45AM

No you misunderstand this, macros do not take a detour over 'menu items', as your keystroke-imitation does.
Macros do call the real function directly, that means, the real macrolanguage function: ID_SAVE_FRAME_AS (see my edited posts above)
Menus just call the very same function too.
What macros can NOT do, is imitate keystrokes.

But I still think the core prob is your plan to constantly save the current page, all pages, all day long in 1sec intervalls, thousands times per day! Sounds extremely unhealthy to me, even when only thinking about disk health.
Quote

the normal working on the site shouldn't be hindered by this
If the computer is constantly saving?? With the poor person in front of the screen perhaps trying to select an entry in a probably long dropdown menu or something, and it gets snatched away all the time? Without any chance to manually save anything, because everything gets constantly snatched away? And the computer very busy all the time without any break?

Isn't there any chance that you invent some more event-based trigger...?

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: Zvonko
Date: June 26, 2018 07:11AM

@siria

OK, I understand, ID_SAVE_FRAME_AS is the function, but the funcion includes the dialog. And there is no other function without the dialog. And hermes seems to use the binary module to make the dialog invisible and to input the saving target...

No, no "more event-based trigger" can be invented, the only events happen in the content of the frame.

But all this is no problem at all, if the content of the frame can be saved on the disk automatically. Please believe me, all the other parts of my concept are not a big problem for my SW. Only files with a new content will be preserved and used to extract relevant data, and this is not a significant burden for processor and/or disk at all. And in addition to the automatic saving of the frame content I always can implement manual saving or other actions suitable to extract relevant data. This is an area where I know my way around and can let off steam.



Edited 3 time(s). Last edit at 06/26/2018 11:51AM by Zvonko.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: hermes
Date: June 26, 2018 02:41PM

@Zvonko

Question number one: whether it works (for You) or not?! Problems could be if you are not using English version of OS. Although this can be corrected by a couple of lines. The load on the disk in such cases can easily be leveled using a micro RAM disk. For example, since Gecko (in general) and Goanna (in particular) very often access the hard disk, the browser has been living for a few years only on a micro RAM drive (~128 Mcool smiley.

Good old article on topic of rewriting disk and Firefox profiles:
https://alter.org.ua/en/docs/other/abstractions/

A binary module is doing something that I couldn't make on macro language, namely to read and to route window messages (i.e., to use WinAPi).

The principle of this kit operation is the following: when browser starts, macro create hook on a combination of hot keys to call separate macro and later load separate binary module. The macro activates its settings (without unnecessarily overwriting them, so without unnecessary writing them to disk in prefs.js file). Next, it changes name of browser window what telling to binary module what it will start saving. The module exposes browser window on top of all windows and the save dialog appears behind it. The macro can select of save format (frames can be saved with a page in an additional folder only if select web page complete for saving as saving format). Next, using WinApi, make the window assume that we have clicked save. The module monitors when the save window disappears and removes the flag (on top of all) from browser window. When browser is closed, the module is unloaded from memory. The resource consumption by module is about 480 KB of RAM and 0% CPU.

The save window can be completely invisible this has not been done to simplify debugging.



Edited 1 time(s). Last edit at 06/26/2018 02:46PM by hermes.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: Zvonko
Date: June 26, 2018 04:26PM

@hermes

If I had known that this is such a difficult thing, I would never have dared to ask for help... As I already said, my exception was that there is a simple function and... But there seems to be no way not involving this annoying dialog, am I right?

I now roughly understand what you are doing. A tricky method, indeed, chapeau!

At the moment I am only able to test it at home, on sample pages from the site saved locally on my computer. (I will be able to test it in the practice in a few days.) I see that the browser window is renamed (and inactivated), and if I minimize the browser window, I see the dialog, with _$_ZVONKO_SAVE_$_.htm displayed in the filename field. But nothing else happens. Which is not as intended, right? Yes, we are using a German Windows version...

If you do not have a quick explanation and/or solution, I would suggest that we take a short break. I could perhaps consider whether I could implement your tricky method directly in my SW.

Committed to a thousand thanks,
sincerely,
Z.



Edited 1 time(s). Last edit at 06/26/2018 04:27PM by Zvonko.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: hermes
Date: June 26, 2018 06:17PM

I know what inconsistencies are with dialogue. I need from you name of "Save As" dialog box in German Windows ("Speichern Als" ?!). Or I can make an external configuration file where you can register for any language. If you watched video, it becomes obvious that window should not be noticeable. I can additionally hide it completely, and not just smash it by Z-order.



Edited 2 time(s). Last edit at 06/26/2018 06:25PM by hermes.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: Zvonko
Date: June 26, 2018 06:56PM

"Speichern unter"

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: hermes
Date: June 26, 2018 08:22PM

version 2

ZVONKO_SAVE_v3 (bugfix)

(direct link) https://getfile.dokpub.com/yandex/get/https://yadi.sk/d/lv5Up-Tk3YSiS9 (~14 Kcool smiley

Changes:
A configuration file appeared smiling smiley ( TOOLs \ ZVONKO_SAVE_CFG.ini ).
You can write a window title for any language in it.

Syntax: ALT_SAVE=TEXT

Examples:
(EN) - Save As
(RU) - Сохранить как
(DE) - Speichern unter (at least for now it is written so, you can correct it if is necessary)



Edited 2 time(s). Last edit at 06/26/2018 08:54PM by hermes.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: hermes
Date: June 26, 2018 08:28PM

@Zvonko

Let me remind you that: by default saves in C:\TEMP.
Path can be overridden in a macro. The folder must exist.

Check better on a clean distro.



**note**

In KM, there is a glitch in first appearance of dialogs of saving and searching (sometimes, but not always, Z-order may be lost). With second and subsequent save, everything is smooth.

article
https://docs.microsoft.com/ru-ru/windows/desktop/winmsg/about-window-classes



Edited 3 time(s). Last edit at 06/26/2018 09:05PM by hermes.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: Zvonko
Date: June 27, 2018 06:45AM

@hermes

Yes, working!

The saving folder seems not to follow the C:\Test specification from macro, but this is not relevant at the moment. More relevant to me is the huge amount of data saved. With the manual procedure (Save Frame As, then specifying a text file, e.g. Frame.txt, with Type *.txt) there is just one text file containing the naked textual content of the frame, which is only relevant for extraction of required data...



Edited 1 time(s). Last edit at 06/27/2018 09:05AM by Zvonko.

Options: ReplyQuote
Re: How to invoke context-menu... / Save Frame to fix path
Posted by: hermes
Date: June 27, 2018 03:45PM

@Zvonko

The destination folder can be changed in macro (only change carefully with accounting of original syntax). The easiest option is to simply open macro in Notepad and press [ CTRL ] + [ H ] to replace "TEMP" with "TEST" and [ replace all ]. So there should be no mistake.

Quote

Yes, working!

I realized that it module works for you, but I do not understand can you process or parse file.
How do you analyze it? The frame from folder next to the page can be easily turned into desired view even with OS command interpreter... not to mention own modules for processing.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.