AStuart Posted January 7, 2015 Share Posted January 7, 2015 Hi guys, Absolutely new to any and all scripting and am having a bit of trouble wrapping my mind around it all. I've successfully followed the tutorials, but when it comes to branching out from there, it all just goes straight over my head and I've been unsuccessfully trying to read the manual/forum posts/etc. I was lead to AutoIt based on a Google search for finding a way to automatically update a text-file (or it's filename) with the current date and time. I want this to be opened once every half hour so that this text file is updated with the current date. However, I'm having a bit of trouble with making the executable close itself once the script has run. This basically means that the script can only be run once, as opposed to the every half hour I require. My script is most likely to be extremely simple (and I'm sure there's probably better ways to do things), but still learning. I've tried putting 'Exit' at the end of it, but that did nothing to close the executable. #include <FileConstants.au3> #include <MsgBoxConstants.au3> ; Place at the top of your script ; $g_szVersion = "Office.exe" ; If WinExists($g_szVersion) Then Exit ; It's already running ; AutoItWinSetTitle($g_szVersion) ; Rest of your script goes here Local Const $sFilePath = "C:\Users\Moorabbin KUB\Google Drive\Google Drive Checks\Office.txt" Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE) Send("Today's time/date is {F5}") WinClose("Office - Notepad") WinWaitActive("Notepad", "Save") Send("!s") Cheers Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 7, 2015 Moderators Share Posted January 7, 2015 Are you trying to just write to a file every 30 minutes? If so, there's no need for Win* anything. But your FileOpen() function does open a "New" file (deleting the old one) every time it is ran. You might look at something so simple as: Global $sFilePath = "Drive:\Path\To\File\File.extension" FileWrite($sFilePath, @Hour & ":" & @Min & ":" & @Sec & @CRLF) Those two lines may be all you need, compile, then run with a scheduler... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
TheSaint Posted January 7, 2015 Share Posted January 7, 2015 (edited) SmOke_N no doubt has the right of it, but for your education, this is what is happening with your code. You are using FileOpen, when for your later commands, the Run command would have been needed. With FileOpen, you also need to use FileWrite or FileWriteLine, and then close with FileClose. With Run, you could use the Send command as you've done, providing the Notepad window is active. With Run, your WinClose and WinWaitActive would be appropriate, but as it stands, WinClose has nothing to close, and WinWaitActive waits for something that is never going to happen, which is why your executable never closes. P.S. With FileOpen, you can consider that as opening your text file secretly, as nothing appears or is shown. It is a hidden process, and needs the appropriate commands to work with the handle ($hFileOpen). EDIT You might benefit from looking at the _FileWriteLog command, which doesn't require any other command to send date and time to a text file. Edited January 7, 2015 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now