-2

I've written this code in Script Editor. The program loops once or twice but stops soon after. The purpose of the code is to infinitely play "My heart will go on" on the victim's Mac computer. Instead, it only loops twice and can break quite easily. How can I make this foolproof?

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

1 Answers1

0

Something tells me that “the victim’s Mac” , in which you are referring to, belongs to a lady friend of yours. (And BTW… you may want to consider editing your question and re-word “victim’s”)

If this is the case, and in the spirit of “Guy Code” and “Bro’s Before Ho’s”, I re-vamped your code. This should give you the results you’re looking for.

I made it just a bit more friendly so that when the code is launched, it will activate Spotify and keep running the commands within the repeat loop, only while Spotify is running. It will not keep reactivating Spotify. If the user quits Spotify, the AppleScript stops also.

This AppleScript code works for me using the latest version of 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
wch1zpink
  • 3,026
  • 1
  • 8
  • 19