WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: George Vagenas on September 10, 2014, 04:56:34 PM

Title: A Little Gotcha
Post by: George Vagenas on September 10, 2014, 04:56:34 PM
Add this item to popmenu.mnw
Code (winbatch) Select
;__________________________________________________________________________________________
Tilde Test
      Test = wingetactive()
      pause(`DEBUG PAUSE`, strCat(`Test = `, Test))   ;***DEBUG LINE***
     
      winiconize(Test)
      pause(`DEBUG PAUSE`, strCat(`Test = `, Test))   ;***DEBUG LINE***
      winactivate(Test)



Now run this code to create the test folders
Code (winbatch) Select
   dirchange('C:\')
   Cnts = ''
   Cnt = 0
   while direxist('F00ey' : Cnts)
      Cnts = Cnt+1
      Cnt = Cnt+1
   endwhile
   F00ey = 'F00ey' : Cnts
   dirmake(F00ey)
   dirchange(F00ey)
   dirmake('Test!')
   dirmake('Test~')
   run('Explorer.exe', '"C:\' : F00ey : '"')

   return


Or if you don't like running test scripts then create the following test folders:
C:\F00ey
C:\F00ey\Test!
C:\F00ey\Test~
Now start Explorer, navigate to "C:\F00ey\Test!" and select Tilde Test from popmenu, runs as expected.  Navigate to "C:\F00ey\Test~", repeat Tilde Test and the script errors out with "1041: WinIconze: Window not found"
Title: Re: A Little Gotcha
Post by: ....IFICantBYTE on September 10, 2014, 05:59:46 PM
The ~ tilde means it must match a window title of EXACTLY "Test" to iconize, nothing else as far as I understand it, so if it had any other characters before or after "Test", including an actual tilde in the title, then it won't match, wont find it, and will give you that error.

Sorry if I'm wrong and don't understand what you are asking.. I didn't actually try your example as I don't use popmenu
Title: Re: A Little Gotcha
Post by: George Vagenas on September 11, 2014, 02:54:45 AM
Yes! that's the Gotcha, WinBatch is treating a string variable that contains a tilde the same as a literal string.  Try this script in Studio.
Code (winbatch) Select
   windowontop('', 1)
   dirchange('C:\')
   Cnts = ''
   Cnt = 0
   while direxist('F00ey' : Cnts)
      Cnts = Cnt+1
      Cnt = Cnt+1
   endwhile
   F00ey = 'F00ey' : Cnts
   dirmake(F00ey)
   dirchange(F00ey)
   dirmake('Test!')
   dirmake('Test~')
   Chk = 'C:\' : F00ey : '\Test~'
   run('Explorer.exe', '"' : Chk : '"')
   
   if direxist(Chk) then pause(`DEBUG PAUSE`, 'Folder "' : Chk : '" exists!')
   if winexist(Chk) then pause(`DEBUG PAUSE`, 'Window "' : Chk : '" exists!')
      else pause(`DEBUG PAUSE`, 'Window "' : Chk : '" does not exist!')

:cancel   
   return

How would you check for the existence of a window that has a tilde in its title?  If you run the code in Studio you'll have an Explorer window with the title "C:\F00ey\Test~" which Winbatch says doesn't exist.  Winbatch is treating this line:
Code (winbatch) Select
if winexist(Chk) then pause(`DEBUG PAUSE`, 'Window "' : Chk : '" exists!')
The same as this line:
Code (winbatch) Select
if winexist("C:\F00ey\Test~") then pause(`DEBUG PAUSE`, 'Window "' : Chk : '" exists!') and it shouldn't.
Title: Re: A Little Gotcha
Post by: td on September 11, 2014, 06:48:47 AM
In this case you add a tilde...
Title: Re: A Little Gotcha
Post by: George Vagenas on September 11, 2014, 02:49:39 PM
And which case would that be, the first example or my reply to IFICANTBYTE?  What you seem to be saying is that the script needs to anticipate the possibility that a window's title ends with a tilde? (the only situation that causes a problem)  Maybe the help topic for "partial window names" should be updated to indicate the need for special handling of window titles ending with a tilde.
In my situation where the script is running on my own system its an easy fix and I can modify the actual code to deal with it.  If I actually had a Tilde Test popmenu.mnw item it would now look like this:
Code (winbatch) Select
;__________________________________________________________________________________________
Tilde Test
      Test = wingetactive()
      if strindex(Test, '~', 0, @backscan)==strlen(Test) then Test = Test:'~'
      winiconize(Test)
      pause(`DEBUG PAUSE`, strCat(`Test = `, Test))   ;***DEBUG LINE***
      winactivate(Test)
Title: Re: A Little Gotcha
Post by: td on September 12, 2014, 10:09:17 AM
Or in the case where an end match isn't needed or wanted then just strip off the tilde.