Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Automatic reload of changed script


  • Please log in to reply
57 replies to this topic
skrommel
  • Guests
  • Last active:
  • Joined: --
8) 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

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
That's very innovative, thanks for sharing.

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
great time saver idea!

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
if there's one file attribute that i never really understood ever since DOS days, then its 'archive' .... mind shedding some light skrommel?

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


skrommel
  • Guests
  • Last active:
  • Joined: --
: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.

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
uh-huh...thanx!

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


jamestr
  • Members
  • 98 posts
  • Last active: Jul 03 2008 12:30 AM
  • Joined: 05 Apr 2004
even sweeter!

Tekl
  • Members
  • 814 posts
  • Last active: May 03 2009 03:28 PM
  • Joined: 24 Sep 2004
Hi,

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

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

K-Lel
  • Members
  • 6 posts
  • Last active: Nov 05 2007 09:13 PM
  • Joined: 26 Jun 2004
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

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Can you clarify?

K-Lel
  • Members
  • 6 posts
  • Last active: Nov 05 2007 09:13 PM
  • Joined: 26 Jun 2004
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

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
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:
#z::
Run Recompile.exe "%A_ScriptFullPath%"
ExitApp
For Recompile.ahk:
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.

guivho
  • Members
  • 26 posts
  • Last active: Mar 19 2016 05:59 PM
  • Joined: 04 Jun 2005
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:
SetTimer,UPDATEDSCRIPT,1000

UPDATEDSCRIPT:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
  FileSetAttrib,-A,%A_ScriptFullPath%
  SplashTextOn,,,Updated script,
  Sleep,500
  SplashTextOff
  Reload
}
Return
;ENDOFSCRIPT


Decarlo110
  • Members
  • 303 posts
  • Last active: Feb 12 2006 02:15 AM
  • Joined: 15 Dec 2004
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.opensourc...ition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <>

pwy
  • Guests
  • Last active:
  • Joined: --
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.
$^s::
IfWinActive, %A_ScriptName%
{
   Send, ^s
   SplashTextOn,,,Updated script,
   Sleep,200
   SplashTextOff
   Reload
}
else
   Send, ^s
return