Created
March 31, 2015 19:48
-
-
Save henkman/1f064bdcefc54330706f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #NoTrayIcon | |
| #Region ;**** Directives created by AutoIt3Wrapper_GUI **** | |
| #AutoIt3Wrapper_Icon=spotify.ico | |
| #AutoIt3Wrapper_Outfile=MPCHotkey.exe | |
| #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker | |
| #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** | |
| Const $MPC_EXE = "mpc-hc.exe" | |
| Const $DEFAULT_HOTKEYS[5][2] = [ _ | |
| [4, 0], _ | |
| ["PlayPause", "!e"], _ | |
| ["Stop", "!w"], _ | |
| ["NextTrack", "!d"], _ | |
| ["PreviousTrack", "!s"] _ | |
| ] | |
| Local $processes = ProcessList("MPCHotkey.exe") | |
| If @error or $processes[0][0] == 2 Then | |
| Exit | |
| EndIf | |
| Local $hotkeys = IniReadSection ("spotify.ini", "hotkeys") | |
| If @error Then | |
| $hotkeys = $DEFAULT_HOTKEYS | |
| EndIf | |
| If Not ProcessExists($MPC_EXE) Then | |
| Local $mpc = RegRead("HKEY_CURRENT_USER\Software\MPC-HC\MPC-HC", "ExePath") | |
| If $mpc == "" Then | |
| MsgBox(48, "Error", "Spotify is not installed") | |
| Exit | |
| EndIf | |
| If ShellExecute($mpc) == 1 Then | |
| MsgBox(48, "Error", "Could not start spotify (" & $mpc & ")") | |
| Exit | |
| EndIf | |
| Sleep(250) | |
| Local $tries = 3 | |
| While Not ProcessExists($MPC_EXE) | |
| $tries -= 1 | |
| If $tries == 0 Then | |
| MsgBox(48, "Error", "Could not start spotify (" & $mpc & ")") | |
| Exit | |
| EndIf | |
| Sleep(500) | |
| WEnd | |
| EndIf | |
| For $i = 1 To $hotkeys[0][0] Step 1 | |
| If HotKeySet($hotkeys[$i][1], $hotkeys[$i][0]) == 0 Then | |
| MsgBox(48, "Error", "Hotkey could not be set") | |
| Exit | |
| EndIf | |
| Next | |
| While ProcessExists($MPC_EXE) | |
| Sleep(1000) | |
| WEnd | |
| Func PlayPause() | |
| Send("{MEDIA_PLAY_PAUSE}") | |
| EndFunc | |
| Func Stop() | |
| Send("{MEDIA_STOP}") | |
| EndFunc | |
| Func NextTrack() | |
| Send("{MEDIA_NEXT}") | |
| EndFunc | |
| Func PreviousTrack() | |
| Send("{MEDIA_PREV}") | |
| EndFunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment