This file ran fine twice then stoped running

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

MDL>1 and MDL>2

Post by Aaron » Thu Apr 26, 2007 4:46 am

This is the message I got when I added,

Code: Select all

MDL>1) waiting for window "Editor - Script_05" to open
WaitWindowOpen>Editor - Script_05
MDL>2) window "Editor - Script_05" has opened - now waiting for it to close
WaitWindowClosed>Editor - Script_05 
MDL>3) window "Editor - Script_05" has closed - processing...
2) window "Editor - Script_05" has opened - now waiting for it to close

But the window was not yet opened. For some reason it thinks the window is already open
Aaron

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu Apr 26, 2007 12:46 pm

Hi Aaron,
Aaron wrote:This is the message I got when I added,

Code: Select all

MDL>1) waiting for window "Editor - Script_05" to open
WaitWindowOpen>Editor - Script_05
MDL>2) window "Editor - Script_05" has opened - now waiting for it to close
WaitWindowClosed>Editor - Script_05 
MDL>3) window "Editor - Script_05" has closed - processing...
2) window "Editor - Script_05" has opened - now waiting for it to close

But the window was not yet opened. For some reason it thinks the window is already open
I created two test macros and am now wondering what is going on as well... perhaps Marcus or one of the others can fill us in.

Please create and save this test script (I called it "Window Watcher"):

Code: Select all

//"Window Watcher" test script for Aaron by jpuziano
//set which window title we want to monitor (comment out the other)
Let>window_title_to_watch=Untitled - Notepad
//Let>window_title_to_watch=Editor - Script_05

MDL>"Window Watcher" Macro Running%CRLF%%CRLF%Now monitoring window title: %window_title_to_watch%%CRLF%%CRLF%(press SHIFT-ESC to abort at any time)

Label>KEEP_WATCHING
MDL>1) waiting for window "%window_title_to_watch%" to open%CRLF%%CRLF%(press SHIFT-ESC to abort at any time)
WaitWindowOpen>%window_title_to_watch%
MDL>2) window "%window_title_to_watch%" has opened - now waiting for it to close%CRLF%%CRLF%(press SHIFT-ESC to abort at any time)
WaitWindowClosed>%window_title_to_watch%
MDL>3) window "%window_title_to_watch%" has closed - let's keep watching%CRLF%%CRLF%(press SHIFT-ESC to abort at any time)
Goto>KEEP_WATCHING
Now create and save this test script, be sure to name it "Script_05":

Code: Select all

//test script for Aaron - this is just a script that will be
//opened and closed in the Macro Scheduler Advanced Editor.

//Another script called "Window Watcher" should be running in the
//backgroup and it should notice when this script "Script_05"
//is opened and closed in the MS Advanced editor and put out dialogs
//announcing what it has seen.
Notepad Window Test:

1) create and save the two macros above
2) make sure you don't have any Notepad windows open
3) run "Window Watcher" and let it keep running in the background
4) open a Notepad window; observe that Window Watcher sees this
5) close the Notepad window, again Window Watcher sees this and resets
6) open a Notepad window again... close... repeat as often as you want, Window Watcher keeps working correctly
7) press SHIFT-ESC to abort the running macro (Window Watcher)

Macro Scheduler Advanced Editor Window Test:

1) edit the "Window Watcher" macro so we will now be watching for a particular script to open in the Macro Scheduler Advanced Editor... the two lines should now look like this:

//Let>window_title_to_watch=Untitled - Notepad
Let>window_title_to_watch=Editor - Script_05

2) save the above change and make sure you don't have any other macros open in the Macro Scheduler Advanced Editor.
3) run "Window Watcher" and let it keep running in the background
4) open script "Script_05" in the Macro Scheduler Advanced Editor; observe that Window Watcher is blind to this (for the moment)
5) close script "Script_05" in the Macro Scheduler Advanced Editor; observe that only now, Window Watcher sees and reports on the open event and starts waiting for the close event... but the close event has already happened... Window Watcher has now been tricked and will wait forever for a window to close that no longer exists.
6) open "Script_05" in the Advanced Editor, close it, open it, close it... nothing can bring Window Watcher back to life.

No doubt, this is the problem that Aaron is talking about.

Can Marcus or anyone explain why Window Watcher works so well watching a Notepad window open and close... but fails when it tries to watch a Macro Scheduler Advanced Editor window open and close?

For double points... can anyone fix Window Watcher so that it works correctly in all cases?

Thanks for being persistant Aaron.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Apr 26, 2007 1:06 pm

Because the editor is not always killed. It is just hidden. Furthermore you would need to run this as an EXE as the act of editing a macro is halting the script that is running (you are trying to do both from the same app).

Add this line to the top of Window Watcher:

//Visible windows only
Let>WF_TYPE=2

Then compile Window Watcher to an EXE. Then run the EXE.

Now try it!
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Thu Apr 26, 2007 2:40 pm

mtettmar wrote:Because the editor is not always killed. It is just hidden. Furthermore you would need to run this as an EXE as the act of editing a macro is halting the script that is running (you are trying to do both from the same app).

Add this line to the top of Window Watcher:

//Visible windows only
Let>WF_TYPE=2

Then compile Window Watcher to an EXE. Then run the EXE.

Now try it!
That's the ticket, works perfectly now, thanks for that Marcus. :)

Aaron, I hope you have Macro Scheduler Pro (includes the compiler) so you can compile this and run it as a stand-alone EXE. You now have the code to watch for "Script_05" and monitor when it is opened in the MS Advanced Editor and when it is closed (made "invisible" actually but same end-effect to the user).

You could now easily add more code to save date/timestamps to a log file for each open and close editing event for "Script_05". A few more changes and you might be able to make it log editing events for all macros.

If you develop this any farther, please share your code with us, I'd be interested in what you come up with.

Good luck and take care.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

Thanks

Post by Aaron » Thu Apr 26, 2007 3:15 pm

Yes I have pro.

Thanks for the help, and when I Finish I will post it
Aaron

Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

Here is what I got so far

Post by Aaron » Fri May 04, 2007 7:01 am

Here is what I got so far, Works fine but I would like to add a dialog with defaut name WORKING but where I could type new name or browse to file .



Code: Select all

Label>START

//Visible windows only
Let>WF_TYPE=2

WaitWindowOpen>Editor - WORKING

WaitWindowClosed>Editor - WORKING



Let>WriteFromFileName=WORKING.scp

Let>WriteFromFile=C:\Documents and Settings\Owner\My Documents\Macro Scheduler\WORKING.scp

Let>WriteToFile=C:\WORKING_Edited.txt

Day>the_day

Month>the_month

Year>the_year

GetTime>time

Let>msg=The Script Named: %WriteFromFileName% was Edited on %the_month%/%the_day%/%the_year% at %time%


WriteLn>%WriteToFile%,result,%msg%




//==================================================================


Label>START_WRITE_EDITED_SCRIPT

ReadLn>%WriteFromFile%,k,line

If>line=##EOF##,finish

WriteLn>%WriteToFile%,result,%line%

Let>k=k+1

Goto>START_WRITE_EDITED_SCRIPT

Label>finish

WriteLn>%WriteToFile%,result,
WriteLn>%WriteToFile%,result,
WriteLn>%WriteToFile%,result,========================================================================
WriteLn>%WriteToFile%,result,                     START NEW EDITED VERSION BELOW
WriteLn>%WriteToFile%,result,========================================================================

Goto>START

Aaron

Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

Help with writing a variable

Post by Aaron » Fri Jul 06, 2007 11:12 pm

OK, I changed this script to backup all my scripts anytime they are saved

How it works is when a .001 file is saved as a backup it writes the new code to the existing file in the bkup_all_scripts folder.

It writes the time and date before each entry then it deletes the original .001 file in the macro scheduler folder.

Here is where Im running into a problem.
When the script is writen to a file it runs the variables before writing them to file.

For instance, Below is my script. SCRIPT #1

Below that is what I get saved to the backup folder. BACKED UP SCRIPT.

Code: Select all

Label>StartLookingForNewFile

Wait>1

let>files=0

let>FN=0

GetFileList>C:\Users\The Man\Documents\Macro Scheduler\*.001,files

Separate>files,;,file_names

Repeat>FN

Let>FN=FN+1

StringReplace>file_names_%FN%,C:\Users\The Man\Documents\Macro Scheduler\,,file_name

       Label>LoopTillNameCount

IfFileExists>C:\Users\The Man\Documents\Macro Scheduler\%file_name%

       Goto>Next

  Else

       Goto>StartLookingForNewFile

Endif

       Label>Next

// Get the Time and Date
GetTime>time
Day>the_day
Month>the_month
Year>the_year
Let>ForwardSlash=/
// Declare Var msg
Let>msg=%ForwardSlash%%ForwardSlash% THIS SCRIPT: %file_name% was Edited on %the_month%/%the_day%/%the_year% at %time%

// Write to File the msg
WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\%file_name%,result,%msg%

%CRLF% %CRLF%

Let>k=1
Label>START

ReadLn>C:\Users\The Man\Documents\Macro Scheduler\%file_name%,k,line

If>line=##EOF##,finish

WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\%file_name%,result,%line%

Let>k=k+1

Goto>START

Label>finish

WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\%file_name%,result,
WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\%file_name%,result,
WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\%file_name%,result,===================================================================
WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\%file_name%,result,                   START NEW EDITED VERSION BELOW
WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\%file_name%,result,===================================================================

IfFileExists>C:\Users\The Man\Documents\Macro Scheduler\%file_name%,DeleteTheFile,NextLine

SRT>DeleteTheFile
DeleteFile>C:\Users\The Man\Documents\Macro Scheduler\%file_name%
END>DeleteTheFile

Label>NextLine

Until>FN,file_names_count

If>FN=file_names_count,StartLookingForNewFile,LoopTillNameCount

This is what I get

Code: Select all

// THIS SCRIPT: Working_Save All Scripts.001 was Edited on 07/06/2007 at 4:58:53 PM
Label>StartLookingForNewFile

Wait>1

let>files=0

let>FN=0

GetFileList>C:\Users\The Man\Documents\Macro Scheduler\*.001,files

Separate>files,;,file_names

Repeat>FN

Let>FN=FN+1

StringReplace>file_names_1,C:\Users\The Man\Documents\Macro Scheduler\,,file_name

       Label>LoopTillNameCount

IfFileExists>C:\Users\The Man\Documents\Macro Scheduler\Working_Save All Scripts.001

       Goto>Next

  Else

       Goto>StartLookingForNewFile

Endif

       Label>Next

// Get the Time and Date
GetTime>time
Day>the_day
Month>the_month
Year>the_year
Let>ForwardSlash=/
// Declare Var msg
Let>msg=// THIS SCRIPT: Working_Save All Scripts.001 was Edited on 07/06/2007 at 4:58:53 PM

// Write to File the msg
WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\Working_Save All Scripts.001,result,// THIS SCRIPT: Working_Save All Scripts.001 was Edited on 07/06/2007 at 4:58:53 PM


 


Let>k=1
Label>START

ReadLn>C:\Users\The Man\Documents\Macro Scheduler\Working_Save All Scripts.001,k,line

If>line=##EOF##,finish

WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\Working_Save All Scripts.001,result,WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\%file_name%,result,%line%

Let>k=k+1

Goto>START

Label>finish

WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\Working_Save All Scripts.001,result,
WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\Working_Save All Scripts.001,result,
WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\Working_Save All Scripts.001,result,===================================================================
WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\Working_Save All Scripts.001,result,                   START NEW EDITED VERSION BELOW
WriteLn>C:\Users\The Man\Documents\BkUp_All_Scripts\Working_Save All Scripts.001,result,===================================================================

IfFileExists>C:\Users\The Man\Documents\Macro Scheduler\Working_Save All Scripts.001,DeleteTheFile,NextLine

SRT>DeleteTheFile
DeleteFile>C:\Users\The Man\Documents\Macro Scheduler\Working_Save All Scripts.001
END>DeleteTheFile

Label>NextLine

Until>FN,file_names_count

If>FN=file_names_count,StartLookingForNewFile,LoopTillNameCount




===================================================================
                   START NEW EDITED VERSION BELOW
===================================================================



Notice this line

Code: Select all

StringReplace>file_names_%FN%,C:\Users\The Man\Documents\Macro Scheduler\,,file_name
This is what I get

Code: Select all

StringReplace>file_names_1,C:\Users\The Man\Documents\Macro Scheduler\,,file_name

also tis line

Let>msg=// THIS SCRIPT: Working_Save All Scripts.001 was Edited on 07/06/2007 at 4:58:53 PM
Here the problem lies.

Can I have the code writen without it running the variable first?



Thank
Aaron

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts