Help! having trouble with WIN-EXIST and BEGIN-UNTIL loop...

nnCron and nnCron LITE discussion

Help! having trouble with WIN-EXIST and BEGIN-UNTIL loop...

Postby LuckMan212 » Mon, 21 Nov 2005, 11:13

can anyone tell me why this task fails? I am tring to make a task that waits for a certain window to appear before continuing. I am having a very hard time to make this work for some strange reason....
Code: Select all
#( test-win-wait
NoActive
Action:
S" explorer.exe /e,/root, C:\MyFolder" GUIStartApp
BEGIN
   PAUSE: 100
   S" C:\MyFolder" WIN-EXIST?
UNTIL
WIN-ACTIVATE: "C:\MyFolder"
WIN-MOVE: 100 100
1000 740 WIN-RESIZE
)#
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Nicholas_Nemtsev » Mon, 21 Nov 2005, 12:18

You have forgotten one parameter: 0
Code: Select all
#( test-win-wait
...
0 S" explorer.exe /e,/root, C:\MyFolder" GUIStartApp
...
)#
Nicholas Nemtsev
User avatar
Nicholas_Nemtsev
Site Admin
 
Posts: 857
Joined: Thu, 01 Jul 2004, 22:25
Location: Псков

Postby LuckMan212 » Mon, 21 Nov 2005, 18:23

ok thanks Nikolas, I guess this refers back to my other question, about GUIStartApp, when to use the "0" and when not...

but can you tell me then why the following is not working (sorry I cannot highlight, but it is the code inside the user-click handler) --- do some of these words not work inside this other word definition (user-click) ?? I tried it and the explorer.exe window opens but it seems the BEGIN--UNTIL loop is exited immediately, it does not wait for the WIN-EXIST..... help :oops:
Code: Select all
#( check_temp_folders
AsLoggedUser
SingleInstance
Time: 15 */4 * * * *
VARIABLE temp_list
VARIABLE proc_list
VARIABLE someProcsRunning
VARIABLE warnButDoNothing
VARIABLE force_check
VARIABLE size_in_mb
VARIABLE cur_quota
VARIABLE size_show
VARIABLE quota_size_show
2VARIABLE size
CREATE size_type 66 ALLOT
CREATE quota_size_type 66 ALLOT
CREATE cur_line 258 ALLOT
CREATE cur_proc 258 ALLOT
CREATE cur_folder 258 ALLOT
: user_click
   warnButDoNothing @ 0= IF
      0 S" explorer.exe /e,/root, %QUOTE%%cur_folder COUNT%%QUOTE%" EVAL-SUBST GUIStartApp
      BEGIN
         PAUSE: 100
         S" %QUOTE%%cur_folder COUNT%%QUOTE%" EVAL-SUBST WIN-EXIST?
      UNTIL
      WIN-ACTIVATE: "%cur_folder COUNT%"
      WIN-MOVE: 100 100
      1000 740 WIN-RESIZE
   ELSE
      NOOP
   THEN
;
Action:
someProcsRunning OFF
warnButDoNothing OFF
force_check OFF

FILE-EMPTY: "procs_that_use_temp.txt" NOT FILE-EMPTY: "temp_folders.txt" NOT AND
IF
   \ check for running processes that use temp folders
   S" procs_that_use_temp.txt" R/O OPEN-FILE-SHARED THROW proc_list !
   BEGIN cur_proc 1+ 255 proc_list @ READ-LINE THROW someProcsRunning @ 0= AND WHILE
      cur_proc C!
      \ MSG: "process `%cur_proc COUNT%` checking"
      PROC-EXIST: "%cur_proc COUNT%" IF
         \ MSG: "process `%cur_proc COUNT%` IS running"
         someProcsRunning ON
      THEN
   REPEAT
   DROP
   proc_list @ CLOSE-FILE DROP

   \ check temp folder sizes
   S" temp_folders.txt" R/O OPEN-FILE-SHARED THROW temp_list !
   BEGIN cur_line 1+ 255 temp_list @ READ-LINE THROW warnButDoNothing @ 0= AND WHILE
      cur_line C!
      RE-MATCH: "%cur_line COUNT%" "/(.*):(\d+):(\d)/"
      IF
         \ MSG: "$1 = %$1%" \ $1 = folder name
         \ MSG: "$2 = %$2%" \ $2 = megs
         \ MSG: "$3 = %$3%" \ $3 = if =1 then show warning regardless of someProcsRunning flag
         S" %$1%" EVAL-SUBST cur_folder PLACE
         S" %$2%" EVAL-SUBST S>NUM cur_quota !
         S" %$3%" EVAL-SUBST S>NUM force_check !
         RECURSIVE DIR-SIZE: "%cur_folder COUNT%" size 2!
         size 2@ 1048576 UM/MOD size_in_mb ! DROP
         \ MSG: "size of %cur_folder COUNT% (mb) is: %size_in_mb @%"
         cur_quota @ size_in_mb @ < IF
            \ There is a folder over its quota, now fork depending on whether apps are running
            someProcsRunning @ 0= force_check @ 1 = OR IF
               1000 size_in_mb @ < IF
                  size_in_mb @ 1024 / size_show !
                  S" Gb" size_type PLACE
               ELSE
                  size_in_mb @ size_show !
                  S" Mb" size_type PLACE
               THEN
               1000 cur_quota @ < IF
                  cur_quota @ 1024 / quota_size_show !
                  S" Gb" quota_size_type PLACE
               ELSE
                  cur_quota @ quota_size_show !
                  S" Mb" quota_size_type PLACE
               THEN
               2 BalloonIcon !
               ['] user_click OnBalloonClick !
               BALLOON: "System Notification" "`%cur_folder COUNT%` contains %size_show @% %size_type COUNT% of data and is over its defined quota of %quota_size_show @% %quota_size_type COUNT%.  Click here to open the folder so you can review and delete files as needed."
               PAUSE: 10000
               BALLOON: "" ""
            ELSE
               warnButDoNothing ON
            THEN
         THEN
      ELSE
         MSG: "Error found while parsing the following line:%crlf%%crlf%` %$0% `"
      THEN
   REPEAT
   DROP
   temp_list @ CLOSE-FILE DROP
   warnButDoNothing @ IF
      1 BalloonIcon !
      BALLOON: "System Notification" "At least one of the temp folders being monitored is over its defined quota.  However, an application is running that may be using these files, so cleanup is not required at this time."
      PAUSE: 10000
      BALLOON: "" ""
   THEN
ELSE
   3 BalloonIcon !
   BALLOON: "Folder Monitor Error" "At least one of the following files is missing or empty:%CRLF%%CRLF%procs_that_use_temp.txt%CRLF%temp_folders.txt"
   PAUSE: 10000
   BALLOON: "" ""
THEN
)#
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Mon, 21 Nov 2005, 20:35

I'm not sure I understand your problem correctly. So, you are starting Explorer and open some folder:

0 S" explorer.exe /e,/root, %QUOTE%%cur_folder COUNT%%QUOTE%" EVAL-SUBST GUIStartApp

Then you are starting the loop which will run only one time, just because the Window with '%cur_folder COUNT%' title already exists... It seems everything is working exactly as expected.
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby LuckMan212 » Tue, 22 Nov 2005, 02:18

yes you have it correct, I am starting explorer and opening some folder, but the problem is nnCron is executing "too fast" on my machine -- explorer.exe takes few hundred milliseconds to actually execute and create the Window, so if I dont have the BEGIN-UNTIL loop in there. by the time the window is actually open, nnCron has already passed the WIN-EXIST? and the window is never moved or resized to the correct location.

The problem is the loop part does not seem to be working and in the example above, the window opens in the wrong place and never does get moved.

Do you understand now what I am trying to say? :D
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby VK » Tue, 22 Nov 2005, 13:26

so - why you just don't set a 2 or 3 seconds of PAUSE after you open the folder in Explorer?
CU
VK
User avatar
VK
 
Posts: 680
Joined: Wed, 14 Jul 2004, 19:17

Postby LuckMan212 » Tue, 22 Nov 2005, 18:15

because that would be wasteful... it would be better to have the task continue immediately after the window is created...

sometimes if the computer is very busy (running photoshop, for example) then it may take longer than 3 seconds, in which case task will fail... other times the computer is idle and window will open in 100ms.

so I am trying to get this working the proper way
can u help
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby Valery_Kondakoff » Tue, 22 Nov 2005, 21:29

I think you may try to use WIN-WAIT: <time_in_ms> in a separate task, launched by WatchWinCreate:. This separate task will create a flag when a window is up and ready. You can use this flag in your main task.
CU
VK
User avatar
Valery_Kondakoff
Site Admin
 
Posts: 769
Joined: Thu, 01 Jul 2004, 20:49
Location: Moscow, Russia

Postby LuckMan212 » Tue, 22 Nov 2005, 23:15

can u explain how this would be done? I do not know the title or handle of the window ahead of time... it is a dynamic thing
LuckMan212
 
Posts: 133
Joined: Mon, 04 Jul 2005, 11:19

Postby VK » Wed, 23 Nov 2005, 12:52

In general, I was recommending you to move the code from the BEGIN ... UNTIL loop to a separate task, which may looks like this:

Code: Select all
#( separate_task
WatchWinActivate: "ExploreWClass"
Action:
PAUSE: 200
S" %QUOTE%%cur_folder COUNT%%QUOTE%" EVAL-SUBST WIN-EXIST?
IF
WIN-ACTIVATE: "%cur_folder COUNT%"
      WIN-MOVE: 100 100
      1000 740 WIN-RESIZE
THEN
)#
CU
VK
User avatar
VK
 
Posts: 680
Joined: Wed, 14 Jul 2004, 19:17


Return to nnCron forum (English)

Who is online

Users browsing this forum: No registered users and 0 guests

cron