Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

automatically saving WLM drafts (windows live mail)


  • Please log in to reply
7 replies to this topic
me4646
  • Members
  • 13 posts
  • Last active: Apr 19 2012 09:18 PM
  • Joined: 19 Apr 2012
Hello,
I am a total newbie to AHK; I am looking for a way to automatically save WLM (2009) drafts every minute. It should interfere in no way, i.e. there should be no problems when it autosaves whilst one is typing or whilst one is navigating in sub-windows like e.g. spellcheck or search etc. It should also be able to detect the correct window (class:ATH_Note program:C:\Program Files\Windows Live\Mail\wlmail.exe). (The title of the windows changes with the email subject.)

I searched this forum but did not find anything the like, which I found strange since this should to be a frequent need imho... I am a bit fearful doing this myself since I have no experience what I need to take into account. If anyone found this idea useful and would be willing to help or comment to this idea, I'd be really be happy. If it's difficult to implement, I'd be willing to paypal a small amount as a thank you... I really want to keep WLM for various reasons, it's quite good actually.

oh... and it would be nice if it saved a draft also when the window is not active or minimized.

janopn
  • Members
  • 694 posts
  • Last active: Apr 11 2014 08:22 PM
  • Joined: 08 Jul 2011
Hi!
There are at least 2 ways.
Does it saves when you hit ctrl+s? If so, just.set a timer with a 1000ms delay that sends ctrl+s.
But that wont work if app is minimized. The bestway should be this:
Use PROCESS command to check wlmail.exe exists. If so, use CONTROLCLICK command to click the save button. To get the clasNN of the button, use windowspy.
All that inside a timer.
That should work even if app is minimized.

Leef_me
  • Moderators
  • 8114 posts
  • Last active: Today, 02:57 PM
  • Joined: 08 Apr 2009
Hi me4646,
It took longer than I thought to write & test a script.

It should interfere in no way

I can't guarantee this. The script can't tell if the user is using the menus of the draft window.
So instead, it waits until some time after the user has stopped using the mouse or keyboard.

I noticed that if I send the 'save' hotkey to the draft window, it will save everytime.
IMO, this is 'wasteful', so I designed the script to only save if 3 conditions are met:
1. the draft window is active
2. the user was active since the last autosave (mouse or keyboard activity)
3. the time limit has elapsed

It takes care of inactive and minimized draft windows.
If the script detects that no draft windows are open, the script will go 'dormant'
Please read the script to see how it is made active.

; http://www.autohotkey.com/community/viewtopic.php?f=1&t=85296
; Post subject: automatically saving WLM drafts (windows live mail)

; the script works with Windows Live Mail 'draft' windows
/*
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
ahk_class ATH_Note
*/

; if the script detects that no draft windows are open, the script will go 'dormant'
; to re-enable the autosave function, open a draft window 
;	and type one of the 'enabling hotkeys' listed below

autosave_time=60000 ; 1 minute

autosave_time=6000 ; 6 second


diagnostics=1	   ; enable the tooltips
;diagnostics=0	   ; disable the tooltips


threshold:=autosave_time/1000

settimer, saver2, 1000

return




;==============================================================================
; enabling hotkeys
;==============================================================================
;----------- these hotkeys will 'turn on' the autosave function
; -- add more keys as you wish

#ifwinexist ahk_class ATH_Note	
~e::
~space::
~enter::
~Backspace::
;==============================================================================
;==============================================================================

dont_bother = 0 ; enable autosave

settimer, saver2, 1000
return

#ifwinexist 


saver2:
  if b < 0
  {
    if diagnostics
      tooltip, WLM autosave active
    TrayTip ,, WLM autosave active, ,
    sleep, 1000
    tooltip, 
    sleep, 2000
	traytip
    b=0
  }


  ifwinnotexist ahk_class ATH_Note
  {
    settimer, saver2, off

      if diagnostics
        tooltip, WLM autosave dormant
      TrayTip ,, WLM autosave dormant, ,
      b= -2
      sleep, 1000
      tooltip, 
    sleep, 2000

	traytip
    if diagnostics
      tooltip, no draft b_index = %b_index% bother = %dont_bother% idle = %A_TimeIdle% threshold is %threshold%
    return
  }

  b_index++

  IfWinNotActive, ahk_class ATH_Note
  {
    if dont_bother = 1	; the window is active but user is not active and draft was previously saved
    {
      if diagnostics
        tooltip b_index = %b_index% bother = %dont_bother% idle = %A_TimeIdle% threshold is %threshold%
      return
    }
    if diagnostics
      tooltip, WinNotActive b_index = %b_index% bother = %dont_bother% idle = %A_TimeIdle% threshold is %threshold%
      if (b_index >= threshold)
      {
        ControlSend, Internet Explorer_Server1 , {control down}s{control up}, ahk_class ATH_Note
        dont_bother = 1	; once saved, there is no reason to save again
	b_index = 0
        if diagnostics
          tooltip, saved WinNotActive b_index = %b_index% bother = %dont_bother% idle = %A_TimeIdle% threshold is %threshold%
      }
  }
  else
  {
    if (A_TimeIdle < autosave_time) ; the window is active and user is active, enable autosave
        dont_bother = 0
    if dont_bother = 1	; the window is active but user is not active and draft was previously saved
    {
      if diagnostics
        tooltip b_index = %b_index% bother = %dont_bother% idle = %A_TimeIdle% threshold is %threshold%
      return
    }

    if diagnostics
      tooltip, Win__is__Active b_index = %b_index% bother = %dont_bother% idle = %A_TimeIdle% threshold is %threshold%
      if (b_index >= threshold)
      {
	if (A_TimeIdle > autosave_time) ; if inactive long enough, save
	{
          ControlSend, Internet Explorer_Server1 , {control down}s{control up}, ahk_class ATH_Note
	  dont_bother = 1	; once saved, there is no reason to save again
  	  b_index = 0
          if diagnostics
            tooltip, saved Win__is__Active b_index = %b_index% bother = %dont_bother% idle = %A_TimeIdle% threshold is %threshold%
	}
      }

  }
  return


#singleinstance force
#Persistent


; my debugging tools 
+esc::exitapp
f11::listvars
f12::reload


me4646
  • Members
  • 13 posts
  • Last active: Apr 19 2012 09:18 PM
  • Joined: 19 Apr 2012
Oh my God(/Goddess) :)

(But first of all thanks to janopn fot their welcome and hints.)

But yes, I had that suspicion it will be not that easy to get something that will be a bit more sophisticated and I was secretly hoping for someone to feel tempted to write a script. --> Thanks a LOT and thanks so much, Leef_me!!! I will be testing this soon, and if it works it might have a potential to become quite popular actually, if I am not mistaken...

Regards and thanks again.

m.

me4646
  • Members
  • 13 posts
  • Last active: Apr 19 2012 09:18 PM
  • Joined: 19 Apr 2012
hello!
I'd like ask some question with regard to the script... thanks.
- I think it does not work with multiple message windows opened, could that be the case?
- shouldn't diagnostics be disabled by default, since they cause a permanent popup at the moues pointer?
- keys: (I suppose it would be best (or at least not wrong) if all keys trigger saving, not just space etc.
- shouldn't there be a semicolon in front of either autosave_time=60000 ; 1 minute OR autosave_time=6000 ; 6 second ? (sorry if that's a stupid question, I have NO idea about coding, just answer yes/no please :)
- In your post, you wrote as condition "the draft window is active". Doesn't this "conflict" with the later "it takes care of inactive windows". As far as I can see, it will also save inactive windows. Shouldn't it read "the draft window is active or has been active."... sorry, I really tried to understand the code but failed :)

Other than that, the script seems to be working well. Thanks again!!
I also checked the menues and thought of various dialogues, as far as I can see, sending ctrl-s will not cause any malfunction/unintended commands.

I only have one question: is it possible that in rare occasions manually typing e.g. "f" will co-incide exactly with the sent ctrl-s command, and cause a diffent command to be executed? (if so, may the button-command that janopn suggested be more useful?)

I also wonder if the script is too complicated / to much trying to not be wasteful, and therefor might make it difficult to work with more than one message window. As a matter of fact, a second message window i opened was NOT saved...

thanks again......

me4646
  • Members
  • 13 posts
  • Last active: Apr 19 2012 09:18 PM
  • Joined: 19 Apr 2012
Hmm, bugs...
it seems like "s" keys are sent to the window once in a while. after some time, there were serveral "ssss" typed into the mail.
I even think that one s got typed into the quickfind box of the wlm inbox mail list, i.e. not within a message window. Don't know for sure if the latter is just a coincidence and I typed it myself.

Leef_me
  • Moderators
  • 8114 posts
  • Last active: Today, 02:57 PM
  • Joined: 08 Apr 2009
>>I think it does not work with multiple message windows opened, could that be the case?
That is true, it does not.

>>shouldn't diagnostics be disabled by default, since they cause a permanent popup at the moues pointer?
why are you asking? make the change.

>>shouldn't there be a semicolon in front of either autosave_time=60000 ; 1 minute OR autosave_time=6000 ; 6 second ?
yes.

>>In your post, you wrote as condition "the draft window is active". Doesn't this "conflict" with the later "it takes care of inactive windows". As far as I can see, it will also save inactive windows. Shouldn't it read "the draft window is active or has been active."...

Probably so.

>>I only have one question: is it possible that in rare occasions manually typing e.g. "f" will co-incide exactly with the sent ctrl-s command, and cause a diffent command to be executed? (if so, may the button-command that janopn suggested be more useful?)

I tried not to let that happen, but I did write "I can't guarantee this."
:arrow: Maybe you should read up on the controlclick command and see what you can do.

>>I also wonder if the script is too complicated / to much trying to not be wasteful, and therefor might make it difficult to work with more than one message window. As a matter of fact, a second message window i opened was NOT saved...

Already answered

>>Hmm, bugs...
>>it seems like "s" keys are sent to the window once in a while. after some time, there were serveral "ssss" typed into the mail.

I don't believe so.

Multiple instances was not part of your original request.
I'll have to think on that for a while.

me4646
  • Members
  • 13 posts
  • Last active: Apr 19 2012 09:18 PM
  • Joined: 19 Apr 2012
Hello!

I have been testing the script in the meantime, and it consistently produces several "s" typed into the mail draft. In fact, once it even caused a ctrl-shift-s to be sent to the window (a signature template was pasted).
I read up on the controlclick command, however it seemed to me that this possible won't be more reliable.

Do you have any idea how the many s (it's like e.g. 5 in half an hour) get typed into that window? (I've usually been surfing or typing
during the tests, nothing special.)

thanks for your comments.