Rawox Posted April 28, 2010 Posted April 28, 2010 (edited) Hi there, I just updated my iTunesNumpad controller (Control iTunes using your numpad ) Realy usefull when you're in games...And I always seem to get this error from now on:C:\Program Files (x86)\AutoIt3\Include\iTunes.au3 (74) : ==> Variable must be of type "Object".: $iTunesApp.PlayPause $iTunesApp^ ERRORThis is my (simple) code:expandcollapse popup;#NoTrayIcon #include <iTunes.au3> Global $Origin = 100 Global $Registered = False Global $Unregistered = False AdlibRegister ( "checkiTunes", 1200 ) Func checkiTunes() ConsoleWrite ( "Checking" & @CRLF ) If ProcessExists ( "iTunes.exe" ) Then If $Registered = False Then ConsoleWrite ( "Registering" & @CRLF ) registerHotkeys() EndIf Else If $Unregistered = False Then ConsoleWrite ( "Unregistering" & @CRLF ) unRegisterHotkeys() EndIf EndIf EndFunc Func registerHotkeys() ConsoleWrite ( "Registered" & @CRLF ) HotKeySet ( "{NUMPAD0}", "iTunesMute" ) HotKeySet ( "{NUMPAD2}", "soundDown" ) HotKeySet ( "{NUMPAD4}", "prevSong" ) HotKeySet ( "{NUMPAD5}", "pauzeSong" ) HotKeySet ( "{NUMPAD6}", "nextSong" ) HotKeySet ( "{NUMPAD8}", "soundUp" ) $Registered = True $Unregistered = False EndFunc Func unRegisterHotkeys() ConsoleWrite ( "Unregistered" & @CRLF ) HotKeySet ( "{NUMPAD0}" ) HotKeySet ( "{NUMPAD2}" ) HotKeySet ( "{NUMPAD4}" ) HotKeySet ( "{NUMPAD5}" ) HotKeySet ( "{NUMPAD6}" ) HotKeySet ( "{NUMPAD8}" ) $Unregistered = True $Registered = False EndFunc While 1 Sleep ( 250 ) WEnd Func iTunesMute() If _iTunes_Get_Vol ( ) = 0 Then _iTunes_Vol_Set ( $Origin ) Else $Origin = _iTunes_Get_Vol ( ) _iTunes_Vol_Set ( 0 ) EndIf EndFunc Func soundDown() _iTunes_Vol_Down ( 10 ) EndFunc Func soundUp() _iTunes_Vol_Up ( 10 ) EndFunc Func nextSong() _iTunes_Next() EndFunc Func prevSong() _iTunes_Prev() EndFunc Func pauzeSong() _iTunes_Play_Pause() EndFuncBTW, it makes use of the iTunes UDF (http://www.autoitscript.com/forum/index.php?showtopic=70675)Anyway why this error is given?Thanks in advance,Rawox. Edited April 28, 2010 by Rawox
PsaltyDS Posted April 28, 2010 Posted April 28, 2010 You didn't call _iTunes_Start() in the UDF. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Rawox Posted April 28, 2010 Author Posted April 28, 2010 Stupid... Well, I wanted it to return no errors when I quit iTunes but now, when I quit iTunes it returns: C:\Program Files (x86)\AutoIt3\Include\iTunes.au3 (18) : ==> The requested action with this object has failed.: $Library_Playlist = $iTunesApp.LibraryPlaylist $Library_Playlist = $iTunesApp.LibraryPlaylist^ ERROR Fixed code: expandcollapse popup;#NoTrayIcon #include <iTunes.au3> Global $Origin = 100 Global $Registered = False Global $Unregistered = False AdlibRegister ( "checkiTunes", 1200 ) Func checkiTunes() ConsoleWrite ( "Checking" & @CRLF ) If ProcessExists ( "iTunes.exe" ) Then _iTunes_Start() If $Registered = False Then ConsoleWrite ( "Registering" & @CRLF ) registerHotkeys() EndIf Else _iTunes_Unload ( ) If $Unregistered = False Then ConsoleWrite ( "Unregistering" & @CRLF ) unRegisterHotkeys() EndIf EndIf EndFunc Func registerHotkeys() ConsoleWrite ( "Registered" & @CRLF ) HotKeySet ( "{NUMPAD0}", "iTunesMute" ) HotKeySet ( "{NUMPAD2}", "soundDown" ) HotKeySet ( "{NUMPAD4}", "prevSong" ) HotKeySet ( "{NUMPAD5}", "pauzeSong" ) HotKeySet ( "{NUMPAD6}", "nextSong" ) HotKeySet ( "{NUMPAD8}", "soundUp" ) $Registered = True $Unregistered = False EndFunc Func unRegisterHotkeys() ConsoleWrite ( "Unregistered" & @CRLF ) HotKeySet ( "{NUMPAD0}" ) HotKeySet ( "{NUMPAD2}" ) HotKeySet ( "{NUMPAD4}" ) HotKeySet ( "{NUMPAD5}" ) HotKeySet ( "{NUMPAD6}" ) HotKeySet ( "{NUMPAD8}" ) $Unregistered = True $Registered = False EndFunc While 1 Sleep ( 250 ) WEnd Func iTunesMute() If _iTunes_Get_Vol ( ) = 0 Then _iTunes_Vol_Set ( $Origin ) Else $Origin = _iTunes_Get_Vol ( ) _iTunes_Vol_Set ( 0 ) EndIf EndFunc Func soundDown() _iTunes_Vol_Down ( 10 ) EndFunc Func soundUp() _iTunes_Vol_Up ( 10 ) EndFunc Func nextSong() _iTunes_Next() EndFunc Func prevSong() _iTunes_Prev() EndFunc Func pauzeSong() _iTunes_Play_Pause() EndFunc How to not recieve that error?
zorphnog Posted April 28, 2010 Posted April 28, 2010 (edited) You don't need $Unregistered and $Registered, so just get rid of $Unregistered. You're also running _iTunes_Start every time your checkiTunes function runs and iTunes is running. You should also run _iTunes_Unload after you run unregisterHotKeys. Finally, you will need to reduce the timing of your adlib function, maybe around 250. Try something like this: AdlibRegister("checkiTunes", 250) Func checkiTunes() ConsoleWrite("Checking" & @CRLF) If ProcessExists("iTunes.exe") Then If Not $Registered Then _iTunes_Start() ConsoleWrite("Registering" & @CRLF) registerHotkeys() EndIf Else If $Registered Then ConsoleWrite("Unregistering" & @CRLF) unRegisterHotkeys() _iTunes_Unload() EndIf EndIf EndFunc Edited April 28, 2010 by zorphnog
Rawox Posted April 28, 2010 Author Posted April 28, 2010 Yet another error I tried to figure this out myself, but I don't get why it returns: C:\Program Files (x86)\AutoIt3\Include\iTunes.au3 (288) : ==> The requested action with this object has failed.: $iTunesApp.Quit $iTunesApp.Quit^ ERROR when I quit iTunes...
zorphnog Posted April 28, 2010 Posted April 28, 2010 It happens because the _iTunes_Unload is called after iTunes has already closed. The COM object no longer has an application to reference. You should just remove the _iTunes_Unload call all together and that should fix it. You could additionally delete the object by setting $iTunesApp = 0.Func checkiTunes() ConsoleWrite("Checking" & @CRLF) If ProcessExists("iTunes.exe") Then If Not $Registered Then _iTunes_Start() ConsoleWrite("Registering" & @CRLF) registerHotkeys() EndIf Else If $Registered Then ConsoleWrite("Unregistering" & @CRLF) unRegisterHotkeys() $iTunesApp=0 EndIf EndIf EndFunc
Rawox Posted April 28, 2010 Author Posted April 28, 2010 Ow wow man! That did. Off-topic: Have you been away from the forums for some time? I've never seen you around here and you're a pretty good scripter!
zorphnog Posted April 28, 2010 Posted April 28, 2010 I've been around, just not as active as I used to be. I participate when I have time. Thanks for the compliments.
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