AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SaveDoesReload v1.2 - Function

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
infogulch



Joined: 27 Mar 2008
Posts: 64
Location: KC, MO

PostPosted: Thu Apr 03, 2008 1:21 am    Post subject: SaveDoesReload v1.2 - Function Reply with quote

This is a variation/combination of several other script pieces and ideas mostly taken from Auto Reload of a changed script. I put it into a function format that, after called, it will automatically reload your script if it is changed. (i.e. saved. So, save does reload Wink)
I like having it in my library so I can call it very easily.


Download it.

Code:
/*
SaveDoesReload function

Put this function in your library and call in the auto-exec of your script like this:

SDR()

That's it. Done. Your scipt will reload when you press Ctrl+s
or even the save button of your editor.


Advantages:
# Really easy to add to your script
# Doesn't create any global variables
# Doesn't mess up the auto-execute section by stopping it
# Automatically turns off the tooltip if there was a problem reloading


Recommended Personalizations:
# How often it checks if you save it without the hotkey
   (   SetTimer, SDR_CheckForChange, 1000   )
# Change the tooltip to a splash screen/traytip
# Change %A_ScriptName% to %A_ScriptFullPath% if you editor displays the full path in the title bar
# Change the hotkey label to SDR_CheckForChange to make sure it really saved before you reload it. (recommend a small sleep to give your editor time to actually save it if you do this)
# Change the tooltip number

*/


SDR()
{
   Static SDR_OldUT, SDR_InUse
   
   SetTitleMatchMode, 2
   GroupAdd, SDR_ReloadGroup, %A_ScriptName%
   GroupAdd, SDR_ReloadGroup, SDR.ahk ;reload all scripts with SDR if you modify this file
   
   Hotkey, IfWinActive, ahk_group SDR_ReloadGroup
   Hotkey, ~^s, SDR_Save
   Hotkey, IfWinActive ;reset the #ifwinactive

   FileGetTime, SDR_OldUT, %A_ScriptFullPath%, M ;Old Update time. M: Modification time
   SetTimer, SDR_CheckForChange, 1000
   
   
   SDR_CheckForChange:
   If SDR_InUse      ;so it doesn't try to reload agian if it's already reloading
      return
   FileGetTime, SDR_NewUT, %A_ScriptFullPath%, M
   If (SDR_NewUT = SDR_OldUT) ;if it's different, continue thru to SDR_Save
      Return

   SDR_Save:
      SDR_InUse = 1      ;so it doesn't try to reload agian if it's already reloading
   ToolTip, %A_ScriptName%   -   Updating in 3. ,
   Sleep, 250
   ToolTip, %A_ScriptName%   -   Updating in 2. . ,
   Sleep, 200
   ToolTip, %A_ScriptName%   -   Updating in 1. . . ,
   Sleep, 200
   SetTimer, SDR_Reset, -3000      ;if it hasn't reloaded in 3 seconds, there must've been a problem
   ToolTip, Updating. . . . ,
   Reload
   return

   SDR_Reset:
   FileGetTime, SDR_OldUT, %A_ScriptFullPath%, M
   ToolTip %A_ScriptName%   -   There was a problem reloading.
   Sleep 500
   ToolTip
   SDR_InUse =
   return
}

Credits to everyone from the "Automatic reload..." thread from which I started working on this.

Versions:
1.0 - I don't know why I originally made a new thread for this version, it was basically a combination of some stuff in the other thread.
1.1 - not released. used goto to continue the autoexec section (it seemed messy, so i skipped it)
1.2 - I still don't know if this merits a thread apart from "auto reload of a changed script", but it's here already, so hey. Smile

Comments? Suggestions?
_________________


Last edited by infogulch on Sun May 11, 2008 5:09 am; edited 3 times in total
Back to top
View user's profile Send private message
pockinator



Joined: 06 Dec 2007
Posts: 32

PostPosted: Thu Apr 03, 2008 3:49 pm    Post subject: Reply with quote

Thanks for this! I never even thought to make something like this - I always just hit ^s to save and then my reload hotkey. Very cool. Cool

I'm a bit of a beginner here with AutoHotkey, so I have a question:

What do these lines do in the code?
Code:
;***   <---this and
code
code
code
;*     <---this?
Back to top
View user's profile Send private message
Tally
Guest





PostPosted: Thu Apr 03, 2008 5:35 pm    Post subject: Reply with quote

pockinator wrote:
Thanks for this! I never even thought to make something like this - I always just hit ^s to save and then my reload hotkey. Very cool. Cool

I'm a bit of a beginner here with AutoHotkey, so I have a question:

What do these lines do in the code?
Code:
;***   <---this and
code
code
code
;*     <---this?




; means a comment same with /* comment goes here */

so for example

Code:

; comment about my code
code
code
code

/*
really big comments

big comments
*/


basically, they have no effect on the way the script runs but it helps for you or people who look at your script if you want to explain something etc


(you never see me because i browse here anonymously)
Back to top
infogulch



Joined: 27 Mar 2008
Posts: 64
Location: KC, MO

PostPosted: Thu Apr 03, 2008 7:17 pm    Post subject: Reply with quote

pockinator wrote:
Thanks for this! I never even thought to make something like this - I always just hit ^s to save and then my reload hotkey. Very cool. Cool

I'm a bit of a beginner here with AutoHotkey, so I have a question:

What do these lines do in the code?
Code:
;***   <---this and
code
code
code
;*     <---this?


You're welcome! I find it saves me alot of time, and I thought I'd share it. Smile

Yes, just like Tally wrote, anything after the semicolon is ignored by ahk for the rest of the line, so you can add comments and not be totally confused when you're looking through it. Razz

But those particular lines are for folding in my editor. (Notepad++) It doesn't affect my script, but my editor sees ";***" as the start of a fold, and ";*" as the end of one. If you haven't used folding before, think of it like the folder tree in windows explorer. Click the minus button next to the fold start and it's folded - hiding everything down to the next fold end. It's nice on your eyes, and you can scan through very long scripts if it's folded and you're looking for one specific part.
Back to top
View user's profile Send private message
pockinator



Joined: 06 Dec 2007
Posts: 32

PostPosted: Tue Apr 08, 2008 12:57 am    Post subject: Reply with quote

infogulch wrote:
You're welcome! I find it saves me alot of time, and I thought I'd share it. Smile

Yes, just like Tally wrote, anything after the semicolon is ignored by ahk for the rest of the line, so you can add comments and not be totally confused when you're looking through it. Razz

But those particular lines are for folding in my editor. (Notepad++) It doesn't affect my script, but my editor sees ";***" as the start of a fold, and ";*" as the end of one. If you haven't used folding before, think of it like the folder tree in windows explorer. Click the minus button next to the fold start and it's folded - hiding everything down to the next fold end. It's nice on your eyes, and you can scan through very long scripts if it's folded and you're looking for one specific part.

Oh, okay! I knew that semicolons are for commenting, but I, too, use Notepad++ and noticed the little minus button. I thought it was odd to see a minus button activated by a comment, so I thought it might be a special piece of code that Autohotkey uses. Thanks for the clarification and tip! I'll be sure to use it often. Laughing
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 64
Location: KC, MO

PostPosted: Sun May 11, 2008 4:57 am    Post subject: Reply with quote

I updated it. Linking to and from Automatic reload of changed script
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group