How to save a file before closing it.

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Jmac2501
Pro Scripter
Posts: 76
Joined: Tue Nov 15, 2005 8:11 pm

How to save a file before closing it.

Post by Jmac2501 » Tue Mar 06, 2007 9:50 am

Ok i can't find a way to do this. I Have a program that is always rewriting to the same .txt file. This .txt file stayes open minamized for manual editing by the user when needed. when the user will run the script again it will write to the bottom of the .txt file which i want it to do. my problem is that we keep the .txt file open and not always saved before writing over it with the script. I have the script closing the window, writing the new data and the re-opening the .txt file. But if the .txt file is not saved it just opens a new window under the same name without saving any changes.

SO what i am looking for is a way to save the .txt file, Close the .txt file, then re-open it. I have the last 2 but can't seem to find a way to save the file before closing it.

Any help thanks

here is my script:

Let>workfile=c:\mydocs\test.txt

ifwindowopen>test.txt - Notepad
closewindow>test.txt - Notepad
else
endif

****run main script here****

writeln>workfile,r,newtext
end>workfile
exc>workfile

I have got around this by useing:

SetFocus>test.txt - Notepad
Press ctrl
send>s
closewindow>test.txt - Notepad

But i am looking for a way to save it with out using the setfocus since the .txt file is almost always minamized and am trying to prevent it from opening the window to save it.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Mar 06, 2007 2:20 pm

But i am looking for a way to save it with out using the setfocus since the .txt file is almost always minamized and am trying to prevent it from opening the window to save it.
I don't know of a way to save the txt file while notepad is minimized, but have you thought about opening notepad then immediately moving it off screen. The most the user would see is a blip. When a window is moved off screen you can't send mouse related functions to it but it will accept keyboard related functions.

Try something like:

Code: Select all

IfWindowOpen>Notepad*
  SetFocus>Notepad*
  Wait>0.01
  SetFocus>Notepad*
  Wait>0.01
  MoveWindow>Notepad*,-10000,-10000
  Press Ctrl
  Send>s
  Release Ctrl
  Wait>0.01
  Press Alt
  Send>f
  Release Alt
  Send>x
EndIf
Notice there are two setfocus>. In my experience using setfocus to unminimize a window leaves the window viewable but not yet focused. To resolve that I put in a second setfocus.

Hope this is helpful,
Dick

Jmac2501
Pro Scripter
Posts: 76
Joined: Tue Nov 15, 2005 8:11 pm

Post by Jmac2501 » Wed Mar 07, 2007 1:40 am

Yeah i am using that in my script now but was looking for a better way to save without opeing the window.

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

can you post the script

Post by Aaron » Sat Apr 28, 2007 1:54 am

If you post your script I can help
Aaron

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

OK, I see your script

Post by Aaron » Sat Apr 28, 2007 5:13 am

If your text file is open, and the other program is writing to it, you should be able to close and reopen the txt file and it will be updated.

The only reason it would'nt be is if the other program was not writing to the file properly.

Is the other program written in MS or another language?

If MS I can post a script that will fix your problem.

If not MS, What language is the other program written in?
Aaron

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