Advertisement
Guest User

previewPlay.ahk

a guest
Aug 22nd, 2018
5,474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance Force
  2. ;previews sound files as you select them in explorer
  3.  
  4. oldSelection:=""
  5. Loop {
  6.     ;first wait till explorer is the active window...
  7.     WinWaitActive, ahk_class CabinetWClass
  8.    
  9.     ;next we get the explorer window's com object &
  10.     ;find out what is selected...
  11.     hwnd := WinExist("A")  
  12.     for window in ComObjCreate("Shell.Application").Windows
  13.         if (window.hwnd==hwnd){
  14.             selected := window.document.SelectedItems
  15.             selString := ""
  16.             for item in selected {
  17.                 selString := item.path
  18.                 break ;we only care ahout the first file,
  19.                 ;there has to be a better way of doing this...
  20.                 }
  21.             if( selString != oldSelection) {
  22.                 oldSelection:=selString
  23.                 ;now we have a new selection, send it to soundplay.
  24.                 ;ideally we should check here if it's an audio file,
  25.                 ;but soundplay fails silently, so who cares.
  26.                 ;also: soundPlay works for most files on my system,
  27.                 ;but not all. ex: mp3 & wav play but ogg doesn't
  28.                 SoundPlay, %selString%
  29.                 }
  30.             }
  31.            
  32.     lastInput:=A_TimeIdle
  33.     Loop { ;wait for any input that could change the selected file
  34.         Sleep, 25
  35.         if( A_TimeIdle != lastInput)
  36.             break
  37.         }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement