Home > Mobile >  General help shortening a script from 279 chars to 259 chars MAX
General help shortening a script from 279 chars to 259 chars MAX

Time:08-02

I fully understand this is not exactly the intended purpose of this site and I may get some down votes, but if that comes with one persons help it is worth it

I wrote the following script that is meant to be executed from the run box. Meaning it has to be 259 characters or less

This script will execute and then wait for a mouse movement

After one is detected it will open a youtube video

because they dont play automatically i have to use sendkeys to press the space bar

How can I shorten this by exactly 20 chars?

powershell -w h Add-Type -AssemblyName System.Windows.Forms;
$p=[System.Windows.Forms.Cursor]::Position.X;
while(1){if([Windows.Forms.Cursor]::Position.X-ne$p){break}else{Sleep 3}};
start-process (short-youtube-url);sleep 3;
$o=New-Object -ComObject WScript.Shell;$o.SendKeys(" ")

enter image description here

CodePudding user response:

Does this work?

powershell -w h Add-Type -AssemblyName *m.W*s.F*s;
$w=[Windows.Forms.Cursor];
$p=$w::Position.X;
while(1){if($w::Position.X-ne$p){break}else{Sleep 3}};
saps (short-youtube-url);sleep 3;
$o=New-Object -ComObject WScript.Shell;$o.SendKeys(" ") 
  • Replaced -AssemblyName System.Windows.Forms with asterisks for wildcard matching
  • Set [Windows.Forms.Cursor] into a variable
  • Replaced Start-Process with alias saps
  • Related