Handling iTunes events in PowerShell - Stack Overflow

I have a Windows PowerShell script (running under Windows 11) which polls the iTunes application on the

I have a Windows PowerShell script (running under Windows 11) which polls the iTunes application on the local computer to find out the currently playing track. This could be handled more elegantly by responding to the OnPlayerPlayEvent and OnPlayerStopEvent events. However, I have run out of ideas how to hook an event handler to these events.

What I have tried so far:

$eventHandler = {
    # Do something when the OnPlayerPlayEvent is raised
    Write-Host "iTunes is now playing $($iTunes.CurrentTrack.Name)"
}

$global:iTunes = New-Object -ComObject iTunes.Application
$iTunes.OnPlayerPlayEvent = Register-ObjectEvent -InputObject $global:iTunes -EventName "OnPlayerPlayEvent" -Action $eventHandler -SourceIdentifier "iTunesPlayerPlay"

This outputs the following error message:

Register-ObjectEvent : Cannot register for the specified event. An event with the name 'OnPlayerPlayEvent' does not exist.
Parameter name: eventName

I tried to vary "OnPlayerPlayEvent", like prefixing it with the name of the interface "_IiTunesEvents", or changing to all lowercase, but with no luck.

Resources I have (tried to) use:

  • /?q=itunes%20com - the iTunes COM SDK, to which many places on the internet refer, but it has no helpful examples

After all, I am not even sure whether the problem is with iTunes, with PowerShell, or with how I try to register the event handler.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744290650a4567013.html

相关推荐

  • Handling iTunes events in PowerShell - Stack Overflow

    I have a Windows PowerShell script (running under Windows 11) which polls the iTunes application on the

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信