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 

Automatic reload of changed script
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
skrommel
Guest





PostPosted: Tue Apr 20, 2004 12:38 am    Post subject: Automatic reload of changed script Reply with quote

Cool Just add this to your scripts to have it automatically reload if it is changed!

All it does is set a timer to check if the attrib of the file is A, that is altered, and if so reloads the script.

A real timesaver!
Skrommel

;STARTOFSCRIPT
SetTimer,UPDATEDSCRIPT,1000

UPDATEDSCRIPT:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
SplashTextOn,,,Updated script,
Sleep,500
Reload
}
Return
;ENDOFSCRIPT
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Tue Apr 20, 2004 12:50 am    Post subject: Reply with quote

That's very innovative, thanks for sharing.
Back to top
View user's profile Send private message Send e-mail
Rajat



Joined: 28 Mar 2004
Posts: 1715

PostPosted: Tue Apr 20, 2004 2:03 am    Post subject: Reply with quote

great time saver idea!
_________________
Back to top
View user's profile Send private message
Rajat



Joined: 28 Mar 2004
Posts: 1715

PostPosted: Tue Apr 20, 2004 6:08 am    Post subject: Reply with quote

if there's one file attribute that i never really understood ever since DOS days, then its 'archive' .... mind shedding some light skrommel?
_________________
Back to top
View user's profile Send private message
skrommel
Guest





PostPosted: Tue Apr 20, 2004 9:14 am    Post subject: The A attribute Reply with quote

Idea The A attribute stands for Archive. It's used to tell if a file has changed. Very handy for backups using XCOPY /M to copy only the files changed since the last backup.
Back to top
Rajat



Joined: 28 Mar 2004
Posts: 1715

PostPosted: Tue Apr 20, 2004 10:52 am    Post subject: Reply with quote

uh-huh...thanx!
_________________
Back to top
View user's profile Send private message
jamestr



Joined: 05 Apr 2004
Posts: 96
Location: Connecticut USA

PostPosted: Tue Apr 20, 2004 11:38 pm    Post subject: sweet! Reply with quote

even sweeter!
Back to top
View user's profile Send private message
Tekl



Joined: 24 Sep 2004
Posts: 808
Location: Germany

PostPosted: Fri Oct 29, 2004 2:33 pm    Post subject: Reply with quote

Hi,

I'm a tooltip-fan, so I changed the script, to show a tooltip at the cursor.

Code:

UPDATEDSCRIPT:
   FileGetAttrib,attribs,%A_ScriptFullPath%
   IfInString,attribs,A
   {
      FileSetAttrib,-A,%A_ScriptFullPath%
      posX = %A_CaretX%
      posY = %A_CaretY%
      ToolTip,Updated script,%posX%,%posY%
      Sleep,500
      Reload
   }
Return


Tekl
Back to top
View user's profile Send private message Visit poster's website
K-Lel



Joined: 26 Jun 2004
Posts: 6

PostPosted: Fri Oct 29, 2004 6:05 pm    Post subject: Reply with quote

Hello:
I donīt know so much about it, but how can I replace a script.exe file that is been in use by a #persistent script????

Thanks for All
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Sat Oct 30, 2004 2:06 pm    Post subject: Reply with quote

Can you clarify?
Back to top
View user's profile Send private message Send e-mail
K-Lel



Joined: 26 Jun 2004
Posts: 6

PostPosted: Sat Oct 30, 2004 4:21 pm    Post subject: Reply with quote

Ok, I've a compiled script thas is loaded when start the Pc and never down.
If I want to change it, with a new version, the system send an error because the file is in use.
Can it be replaced in any way?

Thanks
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Sat Oct 30, 2004 4:38 pm    Post subject: Reply with quote

Two possibilities:
1) If possible, don't run it as a compiled script. When run normally, the method in the posts above will work.

2) Launch another EXE or script that runs ahk2exe to re-compile the first script. When it's done, run the original EXE (which is now new because it was recompiled). Something like this:
Code:
#z::
Run Recompile.exe "%A_ScriptFullPath%"
ExitApp

For Recompile.ahk:
Code:
if 1 =  ; No param given.
    ExitApp
Sleep, 200  ; Give the other script time to exit.
SplitPath, 1,, OutDir, OutExtension, OutNameNoExt
Run %ProgramFiles%\AutoHotkey\Compiler\ahk2exe.exe /in "%OutDir%\%OutNameNoExt%.ahk" /out "%1" /icon MyIcon.ico /pass MyPassword

The above will need to be modified if your original script isn't in the same folder as the EXE. It might need other changes for your configuration.
Back to top
View user's profile Send private message Send e-mail
guivho



Joined: 04 Jun 2005
Posts: 26
Location: Lokeren, Belgium

PostPosted: Mon Jun 06, 2005 8:47 pm    Post subject: Re: Automatic reload of changed script Reply with quote

The scriptlet in this post may benefit from a SplashTextOff statement after the Sleep but before the Reload.
This ensures that the SplashText disappears, even if the Reload fails:
Code:

SetTimer,UPDATEDSCRIPT,1000

UPDATEDSCRIPT:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
  FileSetAttrib,-A,%A_ScriptFullPath%
  SplashTextOn,,,Updated script,
  Sleep,500
  SplashTextOff
  Reload
}
Return
;ENDOFSCRIPT
Back to top
View user's profile Send private message
Decarlo110



Joined: 15 Dec 2004
Posts: 303
Location: United States

PostPosted: Tue Jun 07, 2005 2:48 am    Post subject: Reply with quote

Adding SplashTextOff to the end of the routine was my first modification the day i first adopted skrommel's script back in March (which i learned from Example 3 at the end of Wolfgang Reszel's review... it is one of the most useful scripts for those who use AutoHotkey a lot... i had previously been using a hotkey for reload, but automatic is even better), but i later moved the SplashTextOn & Off to immediately before the end of the Configuration section, which also added the visual benefit of indicating when it has reached that point. Plus i use two timers, one for when the .ini file is open (checking every sec) and one for when it is not, checking every 20 sec if it has just been opened.
_________________
1) The Open Source Definition http://www.opensource.org/docs/definition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <<AutoHotkey>>
Back to top
View user's profile Send private message
pwy
Guest





PostPosted: Tue Aug 16, 2005 10:15 pm    Post subject: Auto Reloading Reply with quote

Thank Skrommel for the graet idea. Some how the SetTimer approach did not always work on my computer, so I modified the script as follows, it will reload whenever it is saved.
Code:
$^s::
IfWinActive, %A_ScriptName%
{
   Send, ^s
   SplashTextOn,,,Updated script,
   Sleep,200
   SplashTextOff
   Reload
}
else
   Send, ^s
return
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
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