How to run macros one after the other from the command line API

Hi @JYamamoto

Can you post a complete explanation with all step to run this commands:

$result = PlayAndWait Macro1
$result = PlayAndWait Macro2
$result = PlayAndWait Macro3
$result = PlayAndWait Macro4

I have Windows 7 and firefox 66 with kantu 4.1.6.

I search a solution to run my macros in automatic one after one (with wait to complete work).

Thanks

Hi @JYamamoto

Today i tried script in powershell and it’s the same of a batch file.

To start every macro need to close the previous browser opened and this reset the previous works completed from previous macro.

This solution work with different works, but if I have one site that require 100 xclick/xtype and after i must submit to safe info I can not automatize with this solution.

After Kantu execute 25 xclick/xtype stopped to work, the script close macro, close browser e launch another browser with second macro but lost the previous work.

This solution is the same of batch file that launch browser and macro one after one but not in same browser and same page (that have cookie, cache saved, form filles, login already submit) but in new browser with a new session of site loaded.

Thanks

Hi, I made a screencast that shows how to run one macro after another with the command line. The source code for the Powershell script can be found on on Github.

The command line switches used are:
$arg = “”“file:///”+ $path_autorun_html + “?macro=”+ $macro + “&closeKantu=1&closeBrowser=0&direct=1&savelog=”+$log+“”“”

Hi @TechSupport

I tried this script but every macro close my browser, in the code have taskkill too because every macro to run need browser closed.

I do not know how can continue a macro if the browser need to close.

If the browser remain open firefox notify that firefox is opened and do not run the second macro.

It’s the same of batch file, every macro run firefox + macro and need to closing the lost the previous firefox with all work.

I search a solution to run macro with browser opened and all these script run a firefox instance before run macro, i need to run only macro NOT another instance of firefox that notify that firefox is already open.

I tried batch file and powershell without success because Kantu can not run a macro in automatically with browser opened, have not command to run macro when browser is opened otherwise open new browser with a macro.

Kantu run firefox + macro, NOT only macro this is the diffeence with imacros that can open 1 firefox and unlimited macro without closing firefox.

Actually i do not find any working script to run multiple macros leaving the browser open.

Difference with imacros

Macro javascript of macros run1 firefox (it remain open all day) and run macro one after one

Imacros javascript macro
FIrefox open (rest all day opened)
run macro 1
run macro 2
run macro 1000

Kantu powershell - batch file
Run firefox + macro 1
CLOSE FIREFOX
Run firefox + macro 2
CLOSE FIREFOX
Run firefox + macro 3
CLOSE FIREFOX

Thanks

Hi @TechSupport

Another problem is that powershell do not recognize the time of a macro and use a bad solution to set the time in the script

$timeout_seconds = 60 #max time in seconds allowed for macro to complete (change this value if your macros takes longer to run)

This is a bad solution because if i run 1 macro that require 2 hours and 1 macro that require 10 seconds powershell can not detect the timer for every macro (2 hour and 10 seconds) and use the timer setted in the script.

Imacros detect the exact time of every macros and run one after one in precisely the time required for a macro to complete the job.

Thanks

$timeout_seconds = 60 #max time in seconds allowed for macro to complete
…Imacros detect the exact time of every macros and run one after one in precisely the time required for a macro to complete the job.

Same here! These 60 seconds are the maximum allowed time. If the macro needs more, the “PlayAndWait” command in the script will return with a timeout error, and even terminate Chrome/Firefox if needed, e. g. if the browse hangs. But if the macro runs faster that is no problem.

if i run 1 macro that require 2 hours and 1 macro that require 10 seconds

Then you set $timeout_seconds = 3600*2 :slight_smile: => The 10 seconds macro is still done after 10 seconds. This is just the max. allowed value.

Alternatively, you can also set the timeout on a per macro macro basis:

  • PlayAndWait LongMacro 7200 <= this macros times out after 7201 seconds
  • PlayAndWait ShortMacro 10 <= this macros times out after 11 seconds

I tried this script but every macro close my browser,

Important: You must edit the command line (line 25) and add closeKantu=1 & closeBrowser=0

Then line 25 becomes:
$arg = “”“file:///”+ $path_autorun_html + “?macro=”+ $macro + “&amp;closeKantu=1&amp; closeBrowser=0 &amp;direct=1&amp;savelog=”+$log+""""

If you still encounter problems, please send me a screencast of script and macro running.

I look that with firefox do not work well, have you really tried this firefox ?
I do not use Google Chrome and with firefox this script looks like it doesn’t work well.

I have not tried Firefox, let me test.

Hi @TechSupport

Try with firefox please, in my test the timer do not respect and it’s possibile to run 1 macro only, to run the seconds need to close previous browser (the same case with batch file).

closeBrowser=0 have not effect i switch from 1 and 0 and i look the same result do nothing-

I hope I got something wrong and can fix it but unfortunately I think this script for firefox doesn’t work well.

Thanks

closeBrowser=0 have not effect i switch from 1 and 0 and i look the same result do nothing-

In the macros from the screencast, you must remove the selectWindows | tab=close in the first macro. Because there if no tab to close, this closes the browser :wink:

in my test the timer do not respect

Important: The Firefox download folder must be the same download folder as specified in the script. => Reason: :point_up_2: The script monitors the browser download folder for the Kantu log file to appear! This way it knows when the macro has finished. It also reads this log for the error information, which is in the first line of the log. This is the same in Firefox and in Chrome.

With this done, it works in Firefox, too:

The script is exactly the same as with Chrome. Just the line to start Chrome is now the line to start Firefox.

HI @TechSupport

Today I try again the script and I will apply a lot of attention to the firefox download folder, I write to you as soon as I tried the script again and I tell you if I solved the problems, I thank you

Hi @TechSupport

For me the script continue to NOT working, continue to try to open new firefox.

It is very strange that it works to me it seems that it doesn’t work and every macro opens a new browser, I can’t understand how it is possible that it works for you.

I still look for a serious and working solution for firefox to open a macro after another and I haven’t found anything working,

Have a nice day

Hi @TechSupport

In your video i see a different code of powershell is not the github code, i see some rows different, can be this the problem ?


errorps1

From the error message, Powershell does not know the parameter “-first”. Maybe you have an older version of Powershell. I am on Win 10 and have 5.1. Here is how to check it: Determine installed PowerShell version - Stack Overflow

If your version does not support this paramter, you need to rewrite the script a little bit. What this line does is to read the first line of the Kantu log file.

Hi @Plankton

This error is possible because i use a firefox portable ?

I must edit the line:

cmd = "{env:ProgramFiles}\Mozilla Firefox\firefox.exe"

with

$cmd = “D:\Programmi Installati\Firefox Portable Test 4\FirefoxPortable.exe”

Because my firefox is not installed on windows i use portable version but is the same of firefox installed.

I have windows 7

This is the powershell version

Name Value


CLRVersion 2.0.50727.8762
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1

The first macro run well but at the second reopen the browser and notify that firefox is alrealy opened and do not continue, same with a batch file.

In powershell code of Techsupport i see difference respect the code of powershell found on github can be this the reason ?

The powershell code show taskkill command and this command is used when is necessary to close the browser like my case

{
    $status_text =  "Macro did not complete within the time given:" + $timeout_seconds
    $status_int = -2
    #Cleanup => Kill Chrome instance 
    #taskkill /F /IM chrome.exe /T   
}

I think that this script can work only with taskkill active and browser closed otherwise can not work, this cose can run one macro, close browser and run another macro losing the previous work the powershell code tell this.

Thanks for support

Hi. I’m using your code, but for some reason it never starts the second macros.
Screencast

From the screencast, I see that the powershell script is still waiting for the first macro to finish. Only when it finishes (or reaches timeout) the 2nd macro is started.