Sign in to follow this  
Followers 0
psynegy

iTunes object

6 posts in this topic

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:

#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

Share this post


Link to post
Share on other sites



*dies a little inside*

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Cheers!! But that doesn't seem to release the COM object...

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by psynegy

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0