Sign in to follow this  
Followers 0
leuce

Unsavedchanges logger

4 posts in this topic

#1 ·  Posted (edited)

G'day everyone

Sorry in advance if this request crosses the line of "keylogger" posts.

A colleague of mine often forgets to save his work. He works in a text editor called Metapad. Saving is as simple as pressing Ctrl+S, but you won't believe how many people find even that much effort too much of an effort. My colleague also sometimes presses a keycombination accidently which deletes all information typed thus far (thereby losing hours of work).

So I'd like to have a program that would save the contents of his Metapad editor control whenever the focus goes somewhere else than the Metapad editor.

Theoretically, this should do the trick:

$logfile = FileOpen ("logfile.txt", 1)

Opt("WinTitleMatchMode", 2)

Global $num

While 1
  If WinActive ( "metapad" ) Then
    $num = 1
  Else 
      If $num = 1 Then
        $metapadtext = ControlGetText ( "metapad", "", "RichEdit20A1" )
        FileWrite ($logfile, @CRLF & $metapadtext)
          If $num = 1 Then
            $num = 2
          EndIf
      EndIf
   EndIf
WEnd

...but it doesn't. It doesn't always add the stuff in the Metapad window to the logfile. Any idea about what I'm doing wrong?

Thanks

Samuel

Edited by leuce

Share this post


Link to post
Share on other sites



Widow titles are case sensitive. Could that be the issue?

Share this post


Link to post
Share on other sites

Out of curiosity, how is it actually possible to lose information in a text editor outside of a crash? I can think of only three scenarios that could eventually lead to loss of data (Outside a crash, of course):

  • User closes text editor.
  • User closes active document.
  • User accidentally selects-all + deletes document.
With the first two, the editor should warn about unsaved changes so that the user must intentionally discard the changes. In the third case, undo to the rescue.

So enlighten me, how is your colleague managing to lose data? If I were you, I'd be more interested in fixing the problem at the source than trying to work-around it with an auto-save script. Incidentally, doesn't the editor support auto-save in some capacity?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

So enlighten me, how is your colleague managing to lose data? If I were you, I'd be more interested in fixing the problem at the source than trying to work-around it with an auto-save script. Incidentally, doesn't the editor support auto-save in some capacity?

From his frist post: "My colleague also sometimes presses a keycombination accidently which deletes all information typed thus far (thereby losing hours of work)".

Hm.. I guess what happens is this: His colleague gets really tired and his head drops on the keyboard, accidently pressing CTRL-A and DEL in the right order. Then he rolls his head to the left, which triggers the keys ALT and F4. The warning window stays there for a few minutes just until he scratches his right ear and let his hand fall on ENTER. Yes, I'm pretty sure that's what's going on.... So, let's help him whith the script, as there is a real need for it.

@leuce: You mentioned the solution yourself. "Saving is as simple as pressing Ctrl+S", so why don't you just send CTRL-S to metapad?? BTW: Your script has several logic errors, which prevents it from running correctly.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0