Jump to content

[VBS, Beginner]

heyjay
call WshShell.Run("chrome.exe URL-1")
WScript.Sleep 2000
WshShell.SendKeys "^{p}"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1000
WshShell.SendKeys "ANY-FILE-NAME-1"
WScript.Sleep 100
WshShell.SendKeys "{ENTER}"

I'm not sure if this belongs here to begin with.

 

This is a script that helps me automate task. I have tens of urls that I need to open on a monthly basis and print then as PDF.

 

I see on other posts about a "wait" function that reads if the browser is busy and holds the action until its OK to proceed. It replaces the "sleep" function I think.

 

May I know do I incorporate that "wait" function on my code. I think that it can reduce the amount of time the scripts works.

Link to comment
Share on other sites

Link to post
Share on other sites

In the long term, I think you should get into AutoIT instead of VBS. VBS is kind of dead and it's very limited. There is a library for AutoIT also that allows direct control and interfacing with browsers, so you can do exactly what you need. AutoHotKey is another one, but I prefer AutoIT because the syntax is very similar to VB.

Link to comment
Share on other sites

Link to post
Share on other sites

Another option would be something like greasemonkey extension, maybe in combination with a tool like autoIT or autohotkey.

 

You can write a javascript code in greasemonkey that will run inside the page being loaded and you can catch "on page load complete" event (or something like that) and send the print command to Chrome which will pop up the print window or print to pdf directly. 

 

If it just pops the print window, you can have autoIT or autohotkey monitor the browser and when that window pops up, it can be configured to click on the print button, wait a few seconds and then paste the new address in the browser.

 

Then... repeat until you're out of addresses.

Link to comment
Share on other sites

Link to post
Share on other sites

Another option is puppeteer

const puppeteer = require('puppeteer')

(async () => {
  const browser = await puppeteer.launch({ headless: true });
  const page = await browser.newPage();
  await page.goto('https://google.com', {waitUntil: 'networkidle0'});
  const pdf = await page.pdf({path: 'path/to/save/pdf', format: 'A4' });
  await browser.close();
})();

npm i puppeteer and you ready to go, it downloads chromium for you, no config required

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×