0

I'm trying to create a batch script which opens Spotify and starts the playlist by sending the keypress spacebar

What I got is the following

start chrome.exe "https://play.spotify.com/chart/4rcbQSKQHID0UdZzODxg2Y"
sleep 8
WScript.CreateObject("WScript.Shell").SendKeys("{SPACE}");

which opens the browser with the mentioned website. Sadly nothing happens after that. Anybody got an idea how to solve this problem?

phuclv
  • 32,499
  • 12
  • 130
  • 417
Snackaholic
  • 570
  • 7
  • 26
  • sleep is not a valid command – phuclv Sep 11 '16 at 17:21
  • You aren't saying where to send the keys. `WScript.CreateObject("WScript.Shell").Run """c:\program files\chrome\chrome.exe"" ""https://play.spotify.com/chart/4rcbQSKQHID0UdZzODxg2Y""":WScript.CreateObject("WScript.Shell").AppActivate "Spotify - Chrome":WScript.CreateObject("WScript.Shell").SendKeys " "` –  Sep 11 '16 at 20:42

1 Answers1

1

According to the SendKeys documentation:

To send a space, send the string " ".

So you must send " " instead of {SPACE}

WScript.CreateObject("WScript.Shell").SendKeys(" ");

More importantly, it's a Windows Script Host command so you can't run it directly in a batch file. You must store it in a separate vbs file and then run that file or use a hybrid batch-vbs file. Otherwise you'll get an error like this

'WScript.CreateObject' is not recognized as an internal or external command, operable program or batch file.

phuclv
  • 32,499
  • 12
  • 130
  • 417