Para ejecutar un script AHK después de detectar un EHDD externo USB

Para ejecutar un script AHK después de detectar un EHDD externo USB

Estoy intentando crear un script en AHK (Tecla de acceso rápido automático) para detectar si hay algún disco duro externo conectado y luego ejecutar el siguiente comando en el script. Supongamos que a continuación se muestra el guión.

A
B
C
D
E

Quiero que A a C sea un script para verificar si hay una unidad externa conectada. En caso afirmativo, el comando irá a la línea D o irá a la línea E. Ya revisé algunos scripts pero no tuve suerte. probé el script en esteenlacecomo referencia, pero no estoy seguro de cómo modificarlo según mis necesidades.

Respuesta1

Si conoce la etiqueta de su(s) HDD(s) externo(s), puede usar esto:

; get a list of all the hard drives. Hard drives are considered as FIXED by AHK
DriveGet, drives, list, FIXED
Loop, Parse, drives  ; loop through each drive letter
{
  DriveGet, DriveLabel, Label, %A_LoopField%:  ; get the drive label

  ; IF DriveLabel not contains External HDD1 label,External HDD2 label
  IF (DriveLabel != "External HDD label")  ; If you want to use only one External HDD
    Continue

  ExternalDriveLetter := A_LoopField  ; get the drive letter of the last found

   ;    or 
  ; get the drive letter of the first found
   ; ExternalDriveLetter = %A_LoopField%
     ; Break

}
IfExist, %ExternalDriveLetter%:
    Run %ExternalDriveLetter%:  ; go to line D
else
    MsgBox, No External HDD is connected        ; go to line E

Respuesta2

Loop
{
    WinWaitActive, DiskInDrive   ; put the title in here for the dialog box to wait for indefinitely -- will need to exit from tray

    ; put code here to execute any time the window is active
    ; after code is done, program will loop and wait again

}

Si el cuadro de diálogo no se activa de forma predeterminada, también puede usar WinWait y WinActivate antes de la instrucción WinWaitActive anterior.

información relacionada