How to run a macro from the command line using Chrome

Discussions and Tech Support related to the iMacros Google Chrome extension.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.
honda4life
Posts: 7
Joined: Sat Jul 23, 2011 2:07 pm

How to run a macro from the command line using Chrome

Post by honda4life » Sun Nov 10, 2013 5:12 pm

I followed the wiki.
Not much more information than:

Code: Select all

 <html>
     <head>
         <script language="JavaScript">
             function macro()
             {
                 // Body of the original function on the created macro, i. e.,
                 // from "var m64..." until "...div.dispatchEvent(evt);"
 
                 var m64 = "VkVSU0lPTiUyMEJVSUxEJTNEMTAzMTIwOCUyMFJFQ09SREVSJTNEQ1IlMEFVUkwlMjBHT1RPJTNEaHR0cCUzQSUyRiUyRnd3dy5hbGVydGZveC5jb20lMkYlMEFUQUclMjBQT1MlM0QxJTIwVFlQRSUzREElMjBBVFRSJTNEVFhUJTNBTG9naW4lMEFUQUclMjBQT1MlM0QxJTIwVFlQRSUzRElOUFVUJTNBVEVYVCUyMEZPUk0lM0ROQU1FJTNBZm9ybTElMjBBVFRSJTNESUQlM0FjdGwwM19Mb2dpbiUyMENPTlRFTlQlM0RkZW1vLXJlYWRvbmx5JTQwYWxlcnRmb3guY29tJTBBU0VUJTIwIUVOQ1JZUFRJT04lMjBOTyUwQVRBRyUyMFBPUyUzRDElMjBUWVBFJTNESU5QVVQlM0FQQVNTV09SRCUyMEZPUk0lM0ROQU1FJTNBZm9ybTElMjBBVFRSJTNESUQlM0FjdGwwM19QYXNzd29yZCUyMENPTlRFTlQlM0RkZW1vJTBBVEFHJTIwUE9TJTNEMSUyMFRZUEUlM0RJTlBVVCUzQUNIRUNLQk9YJTIwRk9STSUzRE5BTUUlM0Fmb3JtMSUyMEFUVFIlM0RJRCUzQWN0bDAzX1JlbWVtYmVyTWUlMjBDT05URU5UJTNEWUVTJTBBVEFHJTIwUE9TJTNEMSUyMFRZUEUlM0RJTlBVVCUzQVNVQk1JVCUyMEZPUk0lM0RJRCUzQWZvcm0xJTIwQVRUUiUzRElEJTNBY3RsMDNfTG9naW5CdXR0b24lMEFUQUclMjBQT1MlM0QxJTIwVFlQRSUzREElMjBBVFRSJTNEVFhUJTNBVmlldyUzQ1NQJTNFUGVyZm9ybWFuY2UlM0NTUCUzRUNoYXJ0JTBB", n = "alertfox demo login";if(!/Chrome\/\d+\.\d+\.\d+\.\d+/test(navigator.userAgent)){alert('iMacros: The embedded macros work with iMacros for Chrome. Support for IE/Firefox is planned.');return;}if(!/^(?:chrome|https?|file)/.test(location)){alert('iMacros: To run a macro, you need to open a website first.');return;}var div = document.getElementById("imacros-bookmark-div");if (!div){alert("Can not run macro, no iMacros div found");return;}var ta = document.getElementById("imacros-macro-container");ta.value = decodeURIComponent(atob(m64));div.setAttribute("name", n);var evt = document.createEvent("Event");evt.initEvent("iMacrosRunMacro", true, true);div.dispatchEvent(evt);    
       
             }// end function macro
         </script>
     </head>
     <body onload="macro();"></body>
 </html>
Unfortunately very difficult to read.
So I improved the alignment and added console.debug(document); to find what's wrong:

Code: Select all

<html>
	<head>
		<script language="JavaScript">
			function macro()
                 	{
				var m64 = "VkVSU0lPTiUyMEJVSUxEJTNEMTExMDMxMSUyMFJFQ09SREVSJTNEQ1IlMEFVUkwlMjBHT1RPJTNEd3d3Lmdvb2dsZS5jb20lMEFUQUclMjBQT1MlM0QxJTIwVFlQRSUzRElOUFVUJTNBVEVYVCUyMEZPUk0lM0ROQU1FJTNBZiUyMEFUVFIlM0ROQU1FJTNBcSUyMENPTlRFTlQlM0RoZXR0YXIlM0NTUCUzRXJpZ2dhciUzQ1NQJTNFc3V2aXJlbnQlMEFUQUclMjBQT1MlM0QxJTIwVFlQRSUzRElOUFVUJTNBU1VCTUlUJTIwRk9STSUzRE5BTUUlM0FmJTIwQVRUUiUzRE5BTUUlM0FidG5HJTI2JTI2VkFMVUUlM0FHb29nbGUlM0NTUCUzRVNlYXJjaA=="
		 		var n = "testmakro";
				if(!/Chrome\/\d+\.\d+\.\d+\.\d+/.test(navigator.userAgent)){
					alert('iMacros: The embedded macros work with iMacros for Chrome. Support for IE/Firefox is planned.');
					return;
				}	
				if(!/^(?:chrome|https?|file)/.test(location)){
					alert('iMacros: To run a macro, you need to open a website first.');
					return;
				}
				console.debug(document);
				var div = document.getElementById("imacros-bookmark-div");
				if(!div){
					alert("Can not run macro, no iMacros div found");
					return;
				}
				var ta = document.getElementById("imacros-macro-container");
				ta.value = decodeURIComponent(atob(m64));
				div.setAttribute("name", n);
				var evt = document.createEvent("Event");
				evt.initEvent("iMacrosRunMacro", true, true);
				div.dispatchEvent(evt);
			}// end function macro
		</script>
	</head>
	<body onload="macro();"></body>
</html>
I get the message: Can not run macro, no iMacros div found
When reading the console.debug(document);, i noticed the script searches for a div in the page from the script.
Do I need to add a div with my macro or how does it work? I was thinking it uses the var n = "testmakro"; to select the macro (a bookmark in my case).

A working example should be great.

Chrome version: 30.0.1599.101 (last)
iMacros version: 6.0.6 (last)

Please help, I've spent more than 2 hours trying to solve this issue.

Edit:
firgured out that n is the macro.
That the script creates the bookmark? But can't imagine Chrome allows this, to mess with the bookmarks without notice.
Suspecting macros-bookmark-div is the location from old version.
Need to find new location? But how?
Tom, Tech Support
Posts: 3353
Joined: Mon May 31, 2010 4:59 pm

Re: How to get it working in Chrome

Post by Tom, Tech Support » Mon Nov 11, 2013 11:03 am

Hi honda4life,

Would you please provide a brief description of exactly what you are attempting to accomplish?
Regards,

Tom, iMacros Support
honda4life
Posts: 7
Joined: Sat Jul 23, 2011 2:07 pm

Re: How to get it working in Chrome

Post by honda4life » Mon Nov 11, 2013 11:31 am

I want to start my script with a cronjob on linux :wink:
So I need a way to start it from command line.

Edit:
alert(atob(m64));
alert(decodeURIComponent(atob(m64))); is the macro, so a macro needs to be reverse converted.
This is a problem for later (btoa , encodeURIComponent).

The question remains: What are those 2 lines doing?
var div = document.getElementById("imacros-bookmark-div");, what is the imacros-bookmark-div I guess it's something of iOpus plugin, can't get any further
var ta = document.getElementById("imacros-macro-container");, what is the imacros-macro-container I guess it's something of iOpus plugin, can't get any further
honda4life
Posts: 7
Joined: Sat Jul 23, 2011 2:07 pm

Re: How to get it working in Chrome

Post by honda4life » Wed Nov 13, 2013 9:46 pm

Tom,

Please provide a solution.

Thanks!
Tom, Tech Support
Posts: 3353
Joined: Mon May 31, 2010 4:59 pm

Re: How to get it working in Chrome

Post by Tom, Tech Support » Fri Nov 15, 2013 12:38 pm

Hi honda4life,

The proper procedure is supposed to be as follows:
  1. Create a bookmark for the macro you want to launch
  2. Right-click on the bookmark in Chrome and select Edit
  3. Copy everything in the URL field starting with var e_m64 up to and including window.dispatchEvent(evt);
  4. Paste this code in place of the line starting with var e_m64 in the HTML file shown here.
  5. Start the macro using the rest of the instructions shown here.
Unfortunately, this method is no longer working. I discovered that I could make it work by adding a call to alert() as the first line in the launchMacro() function. Obviously this is not acceptable since it would require user intervention to dismiss the dialog.

I have asked the development team to investigate this further, however, since this approach initially came to us from someone in the user community, there may be someone else who can offer a fix or other approach before we have time to come up with a different solution.
Regards,

Tom, iMacros Support
honda4life
Posts: 7
Joined: Sat Jul 23, 2011 2:07 pm

Re: How to get it working in Chrome

Post by honda4life » Fri Nov 15, 2013 6:44 pm

That's a clever way to store macro's :D

But I only see this:
catch(e){alert('iMacros Bookmarklet error: '+e.toString());}}) ();
So I guess that's another new problem.
It is still possible to open the macro with the extension, edit, play,...
The macro is quite simple, open 2 websites for testing. :wink:

I hope the development team can find a solution.
It's quite strange that a javascript can create/edit a bookmark, that's what the div's supposed to do I think.
This way it would be possible to tamper someone's bookmarks, Chrome, or any other webbrowser can't allow such things.

Thanks for your information.
honda4life
Posts: 7
Joined: Sat Jul 23, 2011 2:07 pm

Re: How to get it working in Chrome

Post by honda4life » Tue Nov 19, 2013 6:58 pm

Spambot? (fifa link)

Friends... Not that much people use iMacros. Asked a few other good programmers btw.
Checking the internet, first thing i've tried, not much useful found.
Believe me, i'm a capable programmer spent hours to solve this problem on my own.
I'm out of options, that's why i'm here.
kri-tof
Posts: 1
Joined: Thu Feb 27, 2014 9:46 am

Re: How to get it working in Chrome

Post by kri-tof » Thu Feb 27, 2014 9:51 am

Hello!

i've found a way to get the "embed in a local page" to work without using alert(), i added this <script></script> before the end of the page like this, at least it works for me

Code: Select all

</body> 
<script language="JavaScript"> 
<!-- 
  window.onload = setTimeout("launchMacro()", 100);
//--> 
</script> 
</html> 
please update the wiki !

kris
kevin.mitnicl
Posts: 4
Joined: Fri Jun 12, 2015 12:36 pm

Re: How to get it working in Chrome

Post by kevin.mitnicl » Fri Jun 12, 2015 12:41 pm

Hy guys,
I need to start imacros from batch file but I don't understand your solution. Can you help me please?
a_shleig_h
Posts: 1
Joined: Tue May 10, 2016 3:58 pm

Re: How to get it working in Chrome

Post by a_shleig_h » Tue May 10, 2016 4:29 pm

Have a "Kind of" Solution...

Firstly, add your macro as a search engine.
In Chrome - Right click the address bar and click Edit Search Engines
Add a new search engine:
name can be whatever you want
Keyword you want to use (I use DL),
URL: You can use the steps above to find your url. Don't take out anything like it tells you to above - it needs to include the whole text from the bookmark.

Now if you type DL into the address bar in Chrome it should start the macro.

Next step is basically create a VBS file which opens chrome and sends keystrokes to hit DL {ENTER}

For the VBS bit just paste the following into a text file and saveas DL.vbs

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell")
'OPEN TWO INSTANCES OF CHROME BECAUSE OF HOMEPAGE
WshShell.Run "chrome.exe", 9
WshShell.Run "chrome.exe", 9

WScript.Sleep 15000

WshShell.SendKeys "DL"
WshShell.SendKeys "{ENTER}"
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: How to get it working in Chrome

Post by iimfun » Wed Jul 27, 2016 3:05 pm

Another workaround to use iMacros for Chrome via the command line.

1. Make sure "Allow access to file URLs" is checked:
http://wiki.imacros.net/iMacros_for_Chr ... mRunner.29

2. Let's assume that file 'D:\Temp\crIimLaunch.html' has the following content:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>Iim Launch</title>
</head>

<body onload="window.setTimeout('document.getElementById(\'criimlaunch\').click();', 1000);">

<script>

var myMacro = 'PROMPT HELLO!' + '\n';
myMacro += 'WAIT SECONDS=1' + '\n';
myMacro += 'PROMPT BYE!' + '\n';

</script>

<a id="criimlaunch" href="javascript:(function() {try{var e_m64 = window.btoa(encodeURIComponent(myMacro)), n64 = 'bWFjcm8uaWlt'; if(!/^(?:chrome|https?|file)/.test(location)){alert('iMacros: Open webpage to run a macro.');return;}var macro = {}; macro.source = decodeURIComponent(atob(e_m64));macro.name = decodeURIComponent(atob(n64));var evt = document.createEvent('CustomEvent');evt.initCustomEvent('iMacrosRunMacro', true, true, macro);window.dispatchEvent(evt);}catch(e){alert('iMacros Bookmarklet error: '+e.toString());}}) ();">Launch CR iMacros</a>

</body>

</html>
3. Example command line / batch file:

Code: Select all

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "file:///D:/Temp/crIimLaunch.html"
Last edited by iimfun on Thu Jul 28, 2016 6:34 am, edited 1 time in total.
sayuto
Posts: 4
Joined: Mon Jul 25, 2016 5:27 pm

Re: How to get it working in Chrome

Post by sayuto » Wed Jul 27, 2016 4:56 pm

iimfun wrote:Another workaround to use iMacros for Chrome via the command line.

1. Make sure "Allow access to file URLs" is checked:
http://wiki.imacros.net/iMacros_for_Chr ... mRunner.29

2. Let's assume that file 'D:\Temp\crIimLaunch.html' has the following content:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>Iim Launch</title>
</head>

<body onload="window.setTimeout('document.getElementById(\'criimlaunch\').click();', 1000);">

<script>
var myIimMacro = 'PROMPT HELLO!' + '\n';
myIimMacro += 'WAIT SECONDS=1' + '\n';
myIimMacro += 'PROMPT BYE!' + '\n';

var myMacro = window.btoa(encodeURIComponent(myIimMacro));
</script>

<a id="criimlaunch" href="javascript:(function() {try{var e_m64 = myMacro, n64 = 'bWFjcm8uaWlt'; if(!/^(?:chrome|https?|file)/.test(location)){alert('iMacros: Open webpage to run a macro.');return;}var macro = {}; macro.source = decodeURIComponent(atob(e_m64));macro.name = decodeURIComponent(atob(n64));var evt = document.createEvent('CustomEvent');evt.initCustomEvent('iMacrosRunMacro', true, true, macro);window.dispatchEvent(evt);}catch(e){alert('iMacros Bookmarklet error: '+e.toString());}}) ();">Launch CR iMacros</a>

</body>

</html>
3. Example command line / batch file:

Code: Select all

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "file:///D:/Temp/crIimLaunch.html"
not work for my chrome x64
sayuto
Posts: 4
Joined: Mon Jul 25, 2016 5:27 pm

Re: How to get it working in Chrome

Post by sayuto » Wed Jul 27, 2016 4:57 pm

kri-tof wrote:Hello!

i've found a way to get the "embed in a local page" to work without using alert(), i added this <script></script> before the end of the page like this, at least it works for me

Code: Select all

</body> 
<script language="JavaScript"> 
<!-- 
  window.onload = setTimeout("launchMacro()", 100);
//--> 
</script> 
</html> 
please update the wiki !

kris
this work but ưhen i open it not run ,need f5
you can add cmd "send f5 "
Tom, Tech Support
Posts: 3353
Joined: Mon May 31, 2010 4:59 pm

Re: How to get it working in Chrome

Post by Tom, Tech Support » Fri Jul 29, 2016 12:52 pm

sayuto wrote:
iimfun wrote:Another workaround to use iMacros for Chrome via the command line.

1. Make sure "Allow access to file URLs" is checked:
http://wiki.imacros.net/iMacros_for_Chr ... mRunner.29

2. Let's assume that file 'D:\Temp\crIimLaunch.html' has the following content:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>Iim Launch</title>
</head>

<body onload="window.setTimeout('document.getElementById(\'criimlaunch\').click();', 1000);">

<script>
var myIimMacro = 'PROMPT HELLO!' + '\n';
myIimMacro += 'WAIT SECONDS=1' + '\n';
myIimMacro += 'PROMPT BYE!' + '\n';

var myMacro = window.btoa(encodeURIComponent(myIimMacro));
</script>

<a id="criimlaunch" href="javascript:(function() {try{var e_m64 = myMacro, n64 = 'bWFjcm8uaWlt'; if(!/^(?:chrome|https?|file)/.test(location)){alert('iMacros: Open webpage to run a macro.');return;}var macro = {}; macro.source = decodeURIComponent(atob(e_m64));macro.name = decodeURIComponent(atob(n64));var evt = document.createEvent('CustomEvent');evt.initCustomEvent('iMacrosRunMacro', true, true, macro);window.dispatchEvent(evt);}catch(e){alert('iMacros Bookmarklet error: '+e.toString());}}) ();">Launch CR iMacros</a>

</body>

</html>
3. Example command line / batch file:

Code: Select all

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "file:///D:/Temp/crIimLaunch.html"
not work for my chrome x64
sayuto,

Are you sure you enabled "Allow access to file URLs" as instructed? I tested this in Chrome 64-bit first without enabling access to file URLs and it did not work for me, but it did work after I enabled that option.

So thank you iimfun for posting this solution! I will update the wiki accordingly very soon.
Regards,

Tom, iMacros Support
sanfric
Posts: 35
Joined: Mon Dec 07, 2009 4:33 pm

Re: How to run a macro from the command line using Chrome

Post by sanfric » Mon Jan 15, 2018 8:28 am

Hi
With Firefox, I use this procedure which works very well

Code: Select all

RetVal = Shell("C:\program files\Firefox\firefox.exe imacros://run/?m=TP.iim")
I followed Tom's procedure to do the same thing with Chrome

Code: Select all

RetVal = Shell("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe file:/// C:\Users\...\Documents\iMacros\Macros/TPS.htm")
Here is the TPS file. htm

Code: Select all

html>
     <body onload="window.setTimeout('document.getElementById(\'criimlaunch\').click();', 1000);">

        <script>
           var e_m64 = " VkVSU0lPTiUyMEJVSUxEJTNEMTAwMSUyMFJFQ09SREVSJTNEQ1IlMEFVUkwlMjBHT1RPJTNEaHR0cCUzQSUyRiUyRmNvcnJlc3BvbmRhbnRzLmxldGVsZWdyYW1tZS5mciUyRldEMTYwQVdQJTJGV0QxNjBBd3AuZXhlJTJGQ09OTkVDVCUyRnBvcnRhaWxfY29yciUzRl9XV1JFRkVSRVJfJTNEJTI2X1dXTkFUSU9OXyUzRDUlMEFUQUclMjBQT1MlM0QxJTIwVFlQRSUzRElNRyUyMEFUVFIlM0RJRCUzQUEyJTBBVEFHJTIwUE9TJTNEMSUyMFRZUEUlM0RTRUxFQ1QlMjBGT1JNJTNETkFNRSUzQVBBR0VfQVJUSUNMRVNfTk9VVkVBVV9URVhURSUyMEFUVFIlM0RJRCUzQUExJTIwQ09OVEVOVCUzRCUyNTM=";
        </script>

 
</script> 

        <a id="criimlaunch" href="javascript:(function() {try{if(!/^(?:chrome|https?|file)/.test(location)){alert('iMacros: Open webpage to run a macro.');return;}var macro = {};macro.source = decodeURIComponent(atob(e_m64));macro.name = 'MacroBookmarklet';var evt = document.createEvent('CustomEvent');evt.initCustomEvent('iMacrosRunMacro', true, true, macro);window.dispatchEvent(evt);}catch(e){alert('iMacros Bookmarklet error: '+e.toString());}}) ();">Launch CR iMacros</a>

     </body>

<
</script> 

 </html>
It works but there are two tabs opened: an useless "TPS.htm" tab with "Lauch Cr iMacros" an after the web page defined in the instructions of the script.

How to have only the web page without the TPS.htm tab ? Or close immédiately this tab?

thank you in advance for your help.
Sanfric
Post Reply