.vbs script works, but not when triggered remotely

Here you are welcome to discuss items of general interest related to Push2Run
Post Reply
stambro
Posts: 5
Joined: Fri Feb 26, 2021 12:14 pm

.vbs script works, but not when triggered remotely

Post by stambro »

Hey Rob, I'm glad you're still at it!

Hi have a VBS script to close Chrome's current tab:

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.AppActivate("Chrome")
WshShell.SendKeys "^w"
WshShell.AppActivate("TextPad"
)

I saved this as Close-Current-Chrome-Tab.vbs

When I simply double-click on it, it works as expected. :D

Then I created a Push2Run card:

Description: close current tab
Listen for: close current tab
Open: close-current-chrome-tab.vbs
Start directory: C:\

When I right click on the card and select Run, it works as expected. :D

I'm using Alexa > ITTT > Pushover

I say, "Alexa trigger close current tab"

Push2Run status: Pushover requested to run - "close current tab" - Action completed successfully

The tab appears to refresh, but that's it. :(
RobLatour
Site Admin
Posts: 1003
Joined: Mon Feb 19, 2018 11:43 am

Re: .vbs script works, but not when triggered remotely

Post by RobLatour »

Well that was an interesting one ...

At first nothing I tried would cause it NOT to work.

It worked when I ran the script by double clicking on it, and it worked when I created a push2run card and ran it directly from the push2run main window (right click run)

It worked when I triggered Push2Run via IFTT and a Google command. I tried this when the .vbs script was stored directly in the c: folder as in your example, as well it worked when I put it in a sub folder of the c: drive.

Eventually however I noticed it did not work if there was no application with an active screen, i.e. the desktop was active but none of the running application had their screens active screen. You can get to that state by having one or more apps open on your desktop and then just left clicking someplace on your desktop's wall paper where no app is running.

Accordingly, it was just a question of making something / anything active; so this is what I did to tweak your script and it seems to be working ok in all cases in my testing now ...

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys ("%{TAB}")
WshShell.AppActivate("Chrome")
WshShell.SendKeys "^w"
WshShell.AppActivate("TextPad")

Hope this helps
Post Reply