使用Powershell暂停Spotify并使用Task Scheduler播放音频

时间:2013-11-11 08:56:38

标签: powershell scheduled-tasks spotify

我已经设法通过任务调度程序的powershell播放声音。现在我想在播放之前停止所有其他音频。 (大部分都是spotify,所以这就是我所关注的。)我尝试使用PSSpotify模块,当它从powershell中执行时就像魅力一样,但是当我从“Run”中激活它时它只播放我的音频。它并没有停止在spotify中播放音乐。我可以杀死spotify过程,但我更喜欢其他方式。

我的剧本:

if (Get-Process -Name spotify) {Invoke-Spotify -stop; Start-Sleep -s 1;}
(New-Object Media.SoundPlayer "Z:\Emil\lunch.wav").Play(); Start-Sleep -s 5; Exit;

我在运行和任务计划程序中输入的内容:

powershell.exe -windowstyle hidden -File "Z:\Emil\lunchen.ps1"

1 个答案:

答案 0 :(得分:0)

我认为您需要明确导入PSSpotify模块。您可以将其添加到ps1文件中,也可以在命令行中执行。

Run Powershell.exe from command line (cmd.exe) with -Command and -File switches?显示您可以:

C:\>Powershell -Command "& {Import-Module PSSpotify}" -File "Z:\Emil\lunchen.ps1"

或者将Import-Module PSSpotify调用放在脚本的顶部也应该这样做。