SciTE: Scriptneustart-Funktion

    • Offizieller Beitrag

    Hi,

    Ich wollte eine Funktion schreiben, um ein Skript in SciTE mit einer Tastenkombination neuzustarten, also abzuschießen und dann neu zu starten.

    Code
    # 44 Restart
    command.44.*="$(SciteDefaultHome)\Restart\Restart.exe" "$(FilePath)"
    command.name.44.*=Restart this script
    command.shortcut.44.*=Ctrl+R

    Restart.au3, kompilieren in C:\Program Files (x86)\AutoIt\SciTE\Restart (oder äquivalent):

    Spoiler anzeigen
    [autoit]

    #include <File.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $szDrive, $szDir, $szFName, $szExt
    if $cmdline[0] == 0 Then Exit
    _killScript($szFName)
    Run('"..\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "' & $CmdLineRaw & '"')

    [/autoit] [autoit][/autoit] [autoit]

    Func _killScript($name)
    ; kill exe
    Run(@ComSpec & "/c taskkill /t /im " & $szFName & ".exe", "")

    [/autoit] [autoit][/autoit] [autoit]

    ; kill au3 run under autoit3.exe
    ; Generated by AutoIt Scriptomatic

    [/autoit] [autoit][/autoit] [autoit]

    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost"

    [/autoit] [autoit][/autoit] [autoit]

    $Output = ""
    $Output = $Output & "Computer: " & $strComputer & @CRLF
    $Output = $Output & "==========================================" & @CRLF
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _
    $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    ConsoleWrite("1")
    If IsObj($colItems) Then
    For $objItem In $colItems
    if ($objItem.Name == "autoi3.exe") and (StringRight($objItem.CommandLine, StringLen($name)) == $name) then
    MsgBox(0, "", $objItem.ProcessId & @CRLF & $objItem.Name & @CRLF & $objItem.CommandLine)
    Run(@ComSpec & "/c taskkill /t /im " & $objItem.ProcessId, "")
    EndIf
    Next
    EndIf
    EndFunc ;==>_killScript

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WMIDateStringToDate($dtmDate)
    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2))
    EndFunc ;==>WMIDateStringToDate

    [/autoit]

    Der Eintrag in der SciTEUser.properties funktioniert auch. Leider wird er wie die anderen Tools ausgegraut, wenn ein Skript läuft und damit habe ich so nichts davon. Weiß jemand, wie ich das verhindern kann?
    Und dann wäre es wohl noch gut, den gefundenen Prozess direkt neuzustarten anstatt ihn zu schließen und dann wieder zu öffnen. Hat da jemand ein Stückchen Code für mich eventuell?

    Danke!
    Johannes

  • ich habe sein lua script angepasst (benutze es für etwas anderes)
    mir geht es nur darum die explorer.exe mit parameter zu öffnen, um den ordner zu öffnen, wo das autoit sctript liegt...
    oder kann das scite schon von hausaus?

    • Offizieller Beitrag

    Hi,

    ich habe mal eine Lösung ausprobiert.
    Folgendes muss getan werden, dann eine Restart-Funktion in Scite zur Verfügung steht.

    In der AutoIt3Warpper.au3 (unter Programme \AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3 ) zu finden.
    in Zeile 1049 dies

    [autoit]

    Run(@ScriptDir & '\Restart.exe ' & '"' & $AutoIT3_PGM & '"', @WorkingDir)

    [/autoit]

    ergänzen.

    Spoiler anzeigen
    [autoit]

    ; Run your script
    Run(@ScriptDir & '\Restart.exe ' & '"' & $AutoIT3_PGM & '"', @WorkingDir)
    $Pid = Run('"' & $AutoIT3_PGM & '" /ErrorStdOut "' & $ScriptFile_In & '" ' & $s_CMDLine, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    EndIf

    [/autoit]

    Dann die AutoItWrapper.au3 neu compilieren. Dies geht nicht, weil die exe ja benutzt wird zum Kompilieren.
    Also vorher in Zeile 4 den Namen ändern

    [autoit]

    #AutoIt3Wrapper_Outfile=_AutoIt3Wrapper.exe

    [/autoit]

    zum Beispiel einen Unterstrich davorsetzen. Dann kompilieren und anschließend die _AutoIt3Wrapper.exe umbenennen, sodass die AutoIt3Wrapper.exe ersetzt wird.

    Im selben Verzeichnis die Restart.exe legen. (hier die au3 die auch vorher noch kompiliert werden muss)

    Spoiler anzeigen
    [autoit]

    ; Restart

    [/autoit] [autoit][/autoit] [autoit]

    Global $WM_COPYDATA = 74

    [/autoit] [autoit][/autoit] [autoit]

    Opt('MustDeclareVars', 1)
    Opt('WinSearchChildren', 1)
    Opt('TrayIconHide', 1)

    [/autoit] [autoit][/autoit] [autoit]

    AdlibRegister('_SelfExit', 1500)
    GUIRegisterMsg($WM_COPYDATA, 'MY_WM_COPYDATA')

    [/autoit] [autoit][/autoit] [autoit]

    ; Variables
    Global $autoit3Exe = 'Autoit3.exe'
    Global $autoit3Wrapper = 'Autoit3wrapper.exe' ; 2x
    Global $sciteExe = 'SciTE.exe'
    Global $sciteWindowClass = '[CLASS:SciTEWindow]'
    ; SciTE variable
    Global $SciTECmd = 0

    [/autoit] [autoit][/autoit] [autoit]

    HotKeySet('^!{F5}', '_restart')

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(500)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _restart()
    AdlibUnRegister('_selfExit')
    While ProcessExists($autoit3Exe) Or ProcessExists($autoit3Wrapper)
    ProcessClose($autoit3Exe)
    ProcessClose($autoit3Wrapper)
    Sleep(500) ; some time before the refresh starts
    _RefreshSystemTray()
    WEnd
    _runScriptInSciTE()
    EndFunc ;==>_restart

    [/autoit] [autoit][/autoit] [autoit]

    ; Activating SciTE and sending the command for "GO" F5
    Func _runScriptInSciTE()
    If Not WinExists($sciteWindowClass, '') Or Not ProcessExists($sciteExe) Then
    MsgBox(16, 'Restart', 'No restart, because there is SciTE running')
    Exit (0)
    EndIf
    SendSciTE_Command('menucommand:420') ; Clear Output
    SendSciTE_Command('output:+> ' & '===============================================================================' & '\n')
    SendSciTE_Command('output:+> Restarting ... --> ' & _scriptName() & '\n')
    SendSciTE_Command('output:+> ' & '===============================================================================' & '\n')
    Sleep(250)
    WinActivate($sciteWindowClass, '')
    SendSciTE_Command('menucommand:' & _checkStableOrBeta()) ; GO
    Exit (0)
    EndFunc ;==>_runScriptInSciTE

    [/autoit] [autoit][/autoit] [autoit]

    ; If no AutoIt3.exe or AutoIt3Wrapper.exe exists, then exit
    Func _SelfExit()
    If ProcessExists($autoit3Exe) = 0 And ProcessExists($autoit3Wrapper) = 0 Then Exit (0)
    EndFunc ;==>_SelfExit

    [/autoit] [autoit][/autoit] [autoit]

    Func _checkStableOrBeta()
    Local $command = 0
    If $cmdLine[0] > 0 Then
    If StringInStr($cmdLine[1], 'beta') = 0 Then
    $command = '303' ; stable
    Else
    $command = '1100' ; beta
    EndIf
    Return $command
    EndIf
    MsgBox(16, 'Stable or Beta', 'Could not find Stable or Beta command')
    Exit(0)
    EndFunc ;==>_checkStableOrBeta

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; Description: Sending commands to SciTE interface
    ;===============================================================================
    Func SendSciTE_Command($sCmd, $Wait_For_Return_Info = 0)
    Local $WM_GETTEXT = 0x000D
    Local $WM_GETTEXTLENGTH = 0x000E224
    Local Const $SCI_GETLINE = 2153
    Local $Scite_hwnd = WinGetHandle('DirectorExtension') ; Get SciTE Director Handle
    Local $My_Hwnd = GUICreate('AutoIt3-SciTE interface') ; Create GUI to receive SciTE info
    Local $My_Dec_Hwnd = Dec(StringTrimLeft($My_Hwnd, 2)) ; Convert my Gui Handle to decimal
    $sCmd = ':' & $My_Dec_Hwnd & ':' & $sCmd ; Add dec my gui handle to commandline to tell SciTE where to send the return info
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']')
    DllStructSetData($CmdStruct, 1, $sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _
    'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _
    'Ptr', DllStructGetPtr($COPYDATA))
    GUIDelete($My_Hwnd)
    EndFunc ;==>SendSciTE_Command
    ;===============================================================================
    ; Description: Sending commands to SciTE interface
    ;===============================================================================
    Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam)
    Local $SciTECmdLen = DllStructGetData($COPYDATA, 2)
    Local $CmdStruct = DllStructCreate('Char[255]', DllStructGetData($COPYDATA, 3))
    $SciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $SciTECmdLen)
    EndFunc ;==>MY_WM_COPYDATA

    [/autoit] [autoit][/autoit] [autoit]

    Func _scriptName()
    Local $opt = Opt('WinTitleMatchMode', 4)
    SendSciTE_Command('askfilename:')
    $SciTECmd = StringReplace($SciTECmd, '\\', '\')
    Local $filename = StringTrimLeft($SciTECmd, StringInStr($SciTECmd, ':', Default, 3))
    Local $scriptDirPath = StringLeft($filename, StringInStr($filename, '\', Default, -1))
    Opt('WinTitleMatchMode', $opt)
    Return StringMid($filename, StringInStr($filename, '\', 2, -1) + 1, 100)
    EndFunc ;==>_scriptName

    [/autoit] [autoit][/autoit] [autoit]

    ; ===================================================================
    ; Removes any dead icons from the notification area.
    ; Parameters:
    ; $nDelay - IN/OPTIONAL - The delay to wait for the notification area to expand with Windows XP's
    ; 'Hide Inactive Icons' feature (In milliseconds).
    ; Returns:
    ; Sets @error on failure:
    ; 1 - Tray couldn't be found.
    ; 2 - DllCall error.
    ; ===================================================================
    Func _RefreshSystemTray($nDelay = 1000)
    ; Save Opt settings
    Local $oldMatchMode = Opt('WinTitleMatchMode', 4)
    Local $oldChildMode = Opt('WinSearchChildren', 1)
    Local $error = 0
    Do; Pseudo loop
    Local $hWnd = WinGetHandle('classname=TrayNotifyWnd')
    If @error Then
    $error = 1
    ExitLoop
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Local $hControl = ControlGetHandle($hWnd, '', 'Button1')

    [/autoit] [autoit][/autoit] [autoit]

    ; We're on XP and the Hide Inactive Icons button is there, so expand it
    If $hControl <> '' And ControlCommand($hWnd, '', $hControl, 'IsVisible', '') Then
    ControlClick($hWnd, '', $hControl)
    Sleep($nDelay)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Local $posStart = MouseGetPos()
    Local $posWin = WinGetPos($hWnd)

    [/autoit] [autoit][/autoit] [autoit]

    Local $y = $posWin[1]
    While $y < $posWin[3] + $posWin[1]
    Local $x = $posWin[0]
    While $x < $posWin[2] + $posWin[0]
    DllCall('user32.dll', 'int', 'SetCursorPos', 'int', $x, 'int', $y)
    If @error Then
    $error = 2
    ExitLoop 3; Jump out of While/While/Do
    EndIf
    $x += 8
    WEnd
    $y += 8
    WEnd
    DllCall('user32.dll', 'int', 'SetCursorPos', 'int', $posStart[0], 'int', $posStart[1])
    ; We're on XP so we need to hide the inactive icons again.
    If $hControl <> '' And ControlCommand($hWnd, '', $hControl, 'IsVisible', '') Then
    ControlClick($hWnd, '', $hControl)
    EndIf
    Until 1

    [/autoit] [autoit][/autoit] [autoit]

    ; Restore Opt settings
    Opt('WinTitleMatchMode', $oldMatchMode)
    Opt('WinSearchChildren', $oldChildMode)
    SetError($error)
    EndFunc ;==>_RefreshSystemTray

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    Anschließend kann in SciTE durch STRG+ALT+F5 das laufende Skript beendet und neu gestartet werden.

    Mega

    P.S: Ich weiß, viel Aufwand, aber manchmal braucht man sowas ja zum Testen :thumbup: