 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
jakemoffatt
Joined: 29 Aug 2009 Posts: 4
|
Posted: Fri Sep 04, 2009 6:52 pm Post subject: Fairly simple script using up 20-25% of my CPU cyles |
|
|
The following script takes an average of 20-25% of my CPU while it is running. Normally not even noticeable for me as I'm using a fairly quick computer. I did notice it today and think that it is excessive.
What can I do to clean it up?
I believe the CPU intensive part is probably the infinite LOOP I have.
Any better way?
What the script does is constantly looks for programs that begin with "Visual DataFlex Studio" and when it finds them, it trims off that text, so that just the "workspace" and "filename" that are loaded into the program appear on the taskbar.
In other words, I just want to remove a few characters from the front of a certain application's window title. It has to constantly loop (I believe) because each time I open a new file the application updates its window title and it needs to be renamed again.
Any tips?
| Code: | #IfWinActive, Visual DataFlex 12.1 Studio
goto, run
Escape::WinClose, Visual DataFlex 12.1 Studio
RenameVDF()
{
If WinExist("Visual DataFlex Studio")
{
SetTitleMatchMode, 1
WinGetTitle, Title
StringReplace, Title, Title, Visual Dataflex Studio 12.1 -
WinSetTitle, %Title%
}
}
CloseImageMan()
{
/*
SetTitleMatchMode, Slow
If WinActive("ahk_class #32770", "ImageMan Developers Toolkit")
{
WinClose
}
SetTitleMatchMode, Fast
*/
}
run:
Loop
{
RenameVDF()
CloseImageMan()
} | [/code] |
|
| Back to top |
|
 |
purloinedheart
Joined: 04 Apr 2008 Posts: 537 Location: Canada
|
Posted: Fri Sep 04, 2009 7:02 pm Post subject: |
|
|
| Try using a SetTimer instead of a loop |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
Posted: Fri Sep 04, 2009 9:31 pm Post subject: Re: Fairly simple script using up 20-25% of my CPU cyles |
|
|
| jakemoffatt wrote: | The following script takes an average of 20-25% of my CPU while it is running.
What the script does is constantly looks for programs that begin with "Visual DataFlex Studio" and when it finds them, it trims off that text, so that just the "workspace" and "filename" that are loaded into the program appear on the taskbar.
Any tips? |
You are inconsistant with your program title, note that 12.1 is shown both before and after Studio; suggest using a program title variable
(not in your case, but a simple variation like this could cause the 'test and rename' function to never rename anything.)
| Code: | # IfWinActive, Visual DataFlex 12.1 Studio
Escape::WinClose, Visual DataFlex 12.1 Studio
If WinExist("Visual DataFlex Studio")
StringReplace, Title, Title, Visual Dataflex Studio 12.1 - |
The goto statement should be before the hotkey definitions (which includes #IfWinActive)
| helpfile wrote: | The Top of the Script (the Auto-execute Section)
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.
|
| Code: | #IfWinActive, Visual DataFlex 12.1 Studio
goto, run
Escape::WinClose, Visual DataFlex 12.1 Studio |
As written, this is like a drum-roll with no ending. I don't know the details of the underlying code, but there are a lot of instructions executed needlessly, not even a chance to 'take a breath' so to speak.
| Code: | Loop
{
RenameVDF()
CloseImageMan()
} |
See the listing below to see the tips implemented. I left out the hotkey and the coded that you had commented out.
Please review the whole listing, there are some variations required for DFS that are not the same as for Notepad
| Code: |
; tested with Notepad, STMM = 2: anywhere in title
SetTitleMatchMode, 2
program = Notepad
; Untested with Visual Dataflex, STMM = 1: must start with the specified
;program = %Visual Dataflex Studio 12.1%
;SetTitleMatchMode, 1
;msgbox '- %program%'
;exitapp
loop
{
; WinWaitActive, %program%,, 2 ; for testing purposes
; WinWait, %program%,, 20 ; as an alternative you could trigger on existance,
; instead of 'active window'
WinWaitActive, %program%,, 20
if (ErrorLevel=1)
{
msgbox,,, not found, .5 ; for testing purposes
continue
}
WinGetTitle, Title
StringReplace, newTitle, Title, - %program% ; for notepad
; StringReplace, newTitle, Title, %program% - ; for Visual DataFlex
WinSetTitle, %Title%, , %newTitle%
} |
Improvements on the above script including commenting out the 'not found' msgbox
and changing the timeout parameter of the preferred winwait??? variant. |
|
| Back to top |
|
 |
jakemoffatt
Joined: 29 Aug 2009 Posts: 4
|
Posted: Fri Sep 04, 2009 9:39 pm Post subject: |
|
|
| Thank you, SetTimer worked and my code looks much cleaner too! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|