Jump to content

My script won't exit


Recommended Posts

Recently, I was getting bored because of quarantine. So I thought maybe let's do some AutoIt.

I recently discovered that you can use the command prompt to run autoit scripts with CmdLine, so I was excited to use it for the first time. I wanted to make a program which "creates" a 2nd clipboard.

So this is how it should work.

- I open cmd

- I type in "filename.au3 [the words that i want to copy]"

- I press enter

- It creates a hotkey to paste the copied word

- It does an empty while loop so it doesn't immediately exit

- To exit the script, I type in "filename.au3 exit".

 

But "filename.au3 exit" doesn't work so I have to manually click on the tray icon which is not what I wanted. I'm fairly new to AutoIt so I don't really know how things work.

Sorry if my English is horrible, it isn't my native language.

Any help would be greatly appreciated.

 

 

Global Const $g_iProfileDir = @UserProfileDir & "\"
Global Const $g_iProgDir = @UserProfileDir & "\Clipify 2.0\" ;dir path
Global Const $g_iIniFile = $g_iProgDir & "config.ini" ;ini file path

DirCreate($g_iProgDir)
Local $iIniRead = IniRead($g_iIniFile, "Setup", "IfExists", "NOEXIST") ; checks if the ini file exists
If $iIniRead = "NOEXIST" Then
    IniWrite($g_iIniFile, "Setup", "IfExists", "1")
    FileMove(@ScriptFullPath, $g_iProfileDir & @ScriptName) ; if it doesn't exist, it'll create the ini file and move the script to the user directory so you don't have to put the entire file path
Else
    Select
        Case $CmdLine[0] = ""
            ToolTip("")
        Case $CmdLine[1] <> "Exit"
            HotKeySet("{TAB}", "_Clip2")
            HotKeySet("`", "_Exit")
            While 1
            WEnd
        Case $CmdLine[1] = "Exit"
            Local $aProcessList = ProcessList(@AutoItPID)
            For $i = 1 To $aProcessList[0][0]
                ProcessClose($aProcessList[$i][1])
            Next
        Case Else ; if it has more than 2 parameters it will automatically exit
            Exit
    EndSelect
EndIf

Func _Clip2()
    Send($CmdLine[1])
EndFunc   ;==>_Clip2

Func _Exit()
    Exit
EndFunc   ;==>_Exit


 

Edited by Jos
codebox added
Link to comment
Share on other sites

Your problem is the ProcessList.  @AutoItPID is unique to each process.  Since you are creating 2 different processes, they have their own individual PID.  Your ProcessList should look for all AutoIt3.exe and close them.  But I would recommend that you close all processes except the one @AutoItPID which should be close normally with Exit.

When you have While...WEnd loop, include a small sleep inside so you do not overload your CPU.

And please use this tool when you post code.  

Link to comment
Share on other sites

21 minutes ago, Nine said:

Your problem is the ProcessList.  @AutoItPID is unique to each process.  Since you are creating 2 different processes, they have their own individual PID.  Your ProcessList should look for all AutoIt3.exe and close them.  But I would recommend that you close all processes except the one @AutoItPID which should be close normally with Exit.

When you have While...WEnd loop, include a small sleep inside so you do not overload your CPU.

And please use this tool when you post code.  

It worked! And I didn't even know that it could overload my CPU.

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...