USB 외부 EHDD 감지 후 AHK 스크립트를 실행하려면

USB 외부 EHDD 감지 후 AHK 스크립트를 실행하려면

연결된 외장 HDD가 있는지 감지하고 스크립트에서 다음 명령을 실행하기 위해 AHK(Auto Hot Key)에서 스크립트를 작성하려고 합니다. 아래가 스크립트라고 가정해 보겠습니다.

A
B
C
D
E

A부터 C까지 외장 드라이브가 연결되어 있는지 확인하는 스크립트가 되도록 하고 싶습니다. 예인 경우 명령은 D 줄로 이동하고 그렇지 않으면 E 줄로 이동합니다. 이미 일부 스크립트를 확인했지만 운이 없습니다. 이것으로 스크립트를 시도했습니다링크참고용이지만 내 요구 사항에 따라 수정하는 방법을 잘 모르겠습니다.

답변1

외장 HDD의 라벨을 알고 있는 경우 다음을 사용할 수 있습니다.

; 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

답변2

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

}

대화 상자가 기본적으로 활성화되지 않으면 위의 WinWaitActive 문 이전에 WinWait 및 WinActivate를 사용할 수도 있습니다.

관련 정보