psynegy Posted July 22, 2007 Share Posted July 22, 2007 Okay, I have a nice and simple script that forwards my media keys on my keyboard to iTunes, wonderful, but because it uses the iTunes COM interface iTunes says it cant quit because an app is using the scripting interface, now, I know from looking at the SDK that there is an "OnQuittingEvent" but I have not got the foggiest of how to call that within AU!! So what I want to do is when I close iTunes, it closes my script as well. There is an obvious pause while iTunes waits for apps to close so it should be piss easy to do, but I can't seem to figure it out. Cheers! My script at the moment: expandcollapse popup#Include <Constants.au3> #NoTrayIcon Opt("TrayMenuMode",1) $exititem = TrayCreateItem("Exit") TraySetIcon("shell32.dll", 157) Global $oiTunes = GetITObject() Func GetITObject() $Object = ObjCreate("iTunes.Application") If Not IsObj($Object) Then MsgBox(0, "Error", "Could not locate iTunes object!") Exit EndIf Return $Object EndFunc Func PlayPause() if GetOpenWindow() Then $State = $oItunes.playerstate Select Case $State = 0 $oiTunes.play Case $State = 1 $oiTunes.pause Case $State = 2 $oiTunes.play Case $State = 3 $oiTunes.play EndSelect EndIf EndFunc Func PreviousTr() if GetOpenWindow() Then $oiTunes.PreviousTrack EndIf EndFunc Func NextTr() if GetOpenWindow() Then $oiTunes.NextTrack EndIf EndFunc Func GetOpenWindow() If WinActive("Media Center") Then return false Else return true EndIf EndFunc $setup = 0 While 1 If WinActive("Media Center") _ Or WinActive("iTunes") _ Or WinActive("Windows Media Player") Then If $setup = 1 Then HotkeySet("{MEDIA_PLAY_PAUSE}") HotkeySet("{MEDIA_NEXT}") HotkeySet("{MEDIA_PREV}") $setup = 0 EndIf Else If $setup = 0 Then HotkeySet("{MEDIA_PLAY_PAUSE}","PlayPause") HotkeySet("{MEDIA_NEXT}","NextTr") HotkeySet("{MEDIA_PREV}","PreviousTr") $setup = 1 EndIf EndIf Sleep(88) $msg = TrayGetMsg() If $msg = $exititem Then ExitLoop WEnd Exit Link to comment Share on other sites More sharing options...
psynegy Posted July 22, 2007 Author Share Posted July 22, 2007 *dies a little inside* Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted July 23, 2007 Moderators Share Posted July 23, 2007 Like this? $oiTunes = _iTunesCreate() If @error Then ConsoleWrite("Could not create iTunes object." & @CR) Exit EndIf $oEvent = ObjEvent($oiTunes, "_EVT_") While 1 Sleep(100) WEnd Func _iTunesCreate() Local $o_object = ObjCreate("iTunes.Application") If Not IsObj($o_object) Then Return SetError(1, 0, 0) Return SetError(0, 0, $o_object) EndFunc Func _EVT_OnAboutToPromptUserToQuitEvent() $oiTunes = 0 Exit EndFunc Link to comment Share on other sites More sharing options...
psynegy Posted July 23, 2007 Author Share Posted July 23, 2007 Cheers!! But that doesn't seem to release the COM object... Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted July 24, 2007 Moderators Share Posted July 24, 2007 Cheers!! But that doesn't seem to release the COM object...If I manually close iTunes with the script running it exits the script and iTunes closes without prompting. Link to comment Share on other sites More sharing options...
psynegy Posted July 24, 2007 Author Share Posted July 24, 2007 (edited) Odd, doesn't do it for me.... Edit: Okay, it did work this time, maybe that was just a one off or something. Edited July 24, 2007 by psynegy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now