Development :  K-Meleon Web Browser Forum
K-Meleon development related discussions. 
New effective macro dev trick: avoid most of AutoIt using 2 console apps
Posted by: rodocop
Date: November 14, 2017 07:35PM

Hi, folks.

Today I will present you small and neat technique that will allow us to expand command power of macros without using comparatively heavyweight and 3rd-party-dependent AutoIt scripts (you are forced to store 2 files in extension package as well as to have AutoIt installed to recompile scripts if needed).

It will be great if we could replace all that stuff with universal and compact command line 'framework' isn't it?! :cool:

And what are you thinking? I have investigated such a 'framework'!

Well. No more empty words.

There are 2 beautiful apps out there.

First is NirCMD: powerful command-line processor able to make numerous useful things for us.

Just look at its syntax and commands list and sure you'll be impressed with all the possibilities!

It's only drawback is its 'consoleness' it works in CMD-window and you know it isn't good thing in user's eyes. Blinking black window... Brrrrr...

Here the next app goes. CHP (Create Hidden Process) is a program to silently launch GUI and console apps in a hidden window.

So we can simply cascade both apps in one command - and get WINDOWLESS operations being processed!

The tutorial itself

1. Download NirCMD, open archive and take only 1 file - nircmdc.exe. This is console version of utility that is most suitable for operating from kmm exec statement.

2. Place this file (once again - nircmdC.exe. Not nircmd.exe!!!) in tools subfolder of KM.

3. Download CHP and place in the same folder.

4. When creating macros define 2 variables:
$CHPpath=getfolder(RootFolder)."\\tools\\chp.exe"; 
$NIRpath=getfolder(RootFolder)."\\tools\\nircmdc.exe";
It worth to make them global as they will be used by a number of future or rewritten macros.

5. Look at this template statement:
exec($CHPpath." ".$NIRpath." closeprocess ultrasurf");
this one silently closes Ultrasurf, for example, in my test macro. (instead of using system taskkill command that is not universal across different Windows - particularly XP has other command instead)

Just playing with NirCMD commands I've created and tested (all works!) such a commands like:
exec($CHPpath." ".$NIRpath." urlshortcut \"http://www.nirsoft.net\" \"~$folder.desktop$\" \"NirSoft\" ");
(creates URL-shortcut to NirSoft homepage on your desktop)

or
exec($CHPpath." "."powercfg /x -monitor-timeout-ac 0");
(forces monitor never to switch off when AC-powered - changes current power scheme)
etc.

So you are welcome folks to play with!

This 'framework' is able to do a big work earlier relying on AutoIt: make changes in Registry, run and close (kill) processes, work with windows, emulate keypresses, copy-paste data, create shortcuts, set system wide timers, manage logoffs/shutdowns and much more!

We'll be able to make KM real control center for our PC!

¡Vamos!



Edited 3 time(s). Last edit at 11/14/2017 07:39PM by rodocop.

Options: ReplyQuote
Re: New effective macro dev trick: avoid most of AutoIt using 2 console apps
Posted by: JamesD
Date: November 15, 2017 01:16PM

This is great. I have just created a favorite for your post. That will save me time searching for it.

Hanlon’s razor is an eponymous adage named after Robert J. Hanlon that states: “Never attribute to malice that which is adequately explained by stupidity.”

JamesD

Options: ReplyQuote
Re: New effective macro dev trick: avoid most of AutoIt using 2 console apps
Posted by: rodocop
Date: November 15, 2017 03:00PM

Never doubted you, James!

Glad you've found it useful!



Edited 2 time(s). Last edit at 11/15/2017 03:02PM by rodocop.

Options: ReplyQuote
One more tool for KM extensions devs
Posted by: rodocop
Date: November 17, 2017 02:36AM

Let's introduce one more useful thing for developers.

Attached is the archive with utility, coded by our comrade hermes.

It's named KMM_TASK_LOGiC.exe and it's supposed to be placed in tools.

================================
NB! -- Don't rename it! -- NB!
================================

After unpack just run to see Help window. This is the only thing it does when run from Windows.
All the stuff we need should be called from KM macros.

The first purpose of this tool is to check whether some program is run at moment or <SEEK> process.

Then tool sends result to clipboard (process found in memory=1, not found=0) or can fire some cmd or app.

Other command is to <KILL> process.

Process could be seeked by name or PID.




My first use of this tool was when creating new extension Don't Sleep. (Read about it in the linked topic, please!)

Here I just want to underline one crucial thing:

it seems to take some non-zero time to seek process and fill clipboard, so using this option avoid getclipboard() in the same macro where <SEEK> is called.

Instead use settimer for 1 second to nested macro, starting with getclipboard() like this:
ds_startcheck{
exec($_kmtl_path." <SEEK> ds.exe <RESULT> CLipBOARD");
settimer(ds_startcheck2,1,free);
}

ds_startcheck2{
$_dsrun=getclipboard();
$_dsrun=="1" ? setpref(BOOL,"kmeleon.pro.macros.dontsleep.sleep.active",false) : setpref(BOOL,"kmeleon.pro.macros.dontsleep.sleep.active",true);
getpref(BOOL,"kmeleon.pro.macros.dontsleep.startup")?&ds_denysleep:0;
}



Edited 5 time(s). Last edit at 11/17/2017 03:03PM by rodocop.

Attachments: KMM_TASK_LOGiC.7z (7.2 KB)  
Options: ReplyQuote


K-Meleon forum is powered by Phorum.