Unix 如何循环播放Spotify曲目的无休止请求?

Unix 如何循环播放Spotify曲目的无休止请求?,unix,applescript,sh,osascript,Unix,Applescript,Sh,Osascript,我已经在脚本编辑器中编写了这段代码。程序循环一两次,但很快就会停止。代码的目的是在受害者的Mac电脑上无限播放“我的心将继续”。相反,它只会循环两次,而且很容易断开。我怎样才能做到万无一失 repeat set volume 10 try using terms from application "Spotify" if player state of application "Spotify" is

我已经在脚本编辑器中编写了这段代码。程序循环一两次,但很快就会停止。代码的目的是在受害者的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电脑”属于你的一位女朋友。(和BTW.……你可能想考虑编辑你的问题并重新定义“受害者”)

如果是这样的话,本着“男人守则”和“兄弟先于何”的精神,我重新修改了你的守则。这会给你你想要的结果

我让它更友好了一点,这样当启动代码时,它将激活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