如何循环播放来自 Spotify 的无休止的请求?



我在脚本编辑器中编写了这段代码。程序循环一两次,但不久后停止。该代码的目的是在受害者的Mac计算机上无限播放"我的心会继续"。相反,它只循环两次,很容易中断。我怎样才能做到万无一失?

repeat
set volume 10
try
using terms from application "Spotify"
if player state of application "Spotify" is paused then
tell application "Spotify" to play
return "unpaused"
end if
end using terms from
tell application "System Events" to (name of processes) contains "Spotify"
if true then
tell application "Spotify"
play track "spotify:track:33LC84JgLvK2KuW43MfaNq" in context "spotify:playlist:2CLbqnKJirVefl8xdtMvEN"
end tell

else
open application "Spotify"
end if
end try
end repeat

有人告诉我,您所指的"受害者的Mac"属于您的一位女朋友。(顺便说一句...您可能需要考虑编辑您的问题并重新措辞"受害者的")

如果是这样的话,本着"Guy Code"和"Bro's Before Ho's"的精神,我重新编写了你的代码。 这应该会给你你想要的结果。

我让它更友好一点,以便在启动代码时,它将激活 Spotify 并在repeat循环中继续运行命令,仅在 Spotify 运行时。它不会继续重新激活Spotify。 如果用户退出Spotify,AppleScript也会停止。

这个AppleScript代码适用于我使用最新版本的macOS Big Sur

use Spotify : application "Spotify" with importing
use scripting additions
if Spotify is not running then launch Spotify
repeat while Spotify is running
set volume 10 -- System Volume
try
set sound volume to 100 -- Spotify Volume
if Spotify is running and Spotify's player state is in {paused, stopped} ¬
and Spotify's current track's spotify url ¬
is in "spotify:track:33LC84JgLvK2KuW43MfaNq" then
play
else if Spotify is running and Spotify's current track's spotify url is not in ¬
"spotify:track:33LC84JgLvK2KuW43MfaNq" then
play track "spotify:track:33LC84JgLvK2KuW43MfaNq" in context ¬
"spotify:playlist:2CLbqnKJirVefl8xdtMvEN"
end if
delay 5
end try
end repeat

最新更新