开发者

Apple Script: How do I get a reference to the next track in iTunes?

开发者 https://www.devze.com 2023-04-04 14:54 出处:网络
What I\'m trying to achieve is this: tell application \"iT开发者_JAVA技巧unes\" play next track with once

What I'm trying to achieve is this:

tell application "iT开发者_JAVA技巧unes"
    play next track with once
end tell

Of course, 'next track' is a command, and not a reference to the next track - so this doesn't work. I've been through the documentation and am really stuck on this - how would I code this so that it works?

If the solution involves making a playlist or anything that's fine - all I need is a script that plays the next song and then stops.

-

Any help is much appreciated :) I've already wasted a lot of time trying to get this to work!


This script is hacky but it works...

tell application "iTunes"
    next track
    set this_track to the name of the current track
    previous track
end tell


After much messing around, this is how I'm doing it. If you can see a better way then I'd like to know!

tell application "iTunes"

    set is_playing to false

    if player state is playing then
        set is_playing to true
    end if

    tell playlist "Cinderella"

        set track_number to 1
        set should_repeat to true
        repeat while should_repeat is true

            if track track_number exists then
                tell track track_number
                    set play_count to (get played count)
                    if play_count is 0 then
                        set should_repeat to false
                    else
                        set track_number to track_number + 1
                    end if
                end tell
            else
                repeat with track_ref in tracks
                    tell track_ref
                        set played count to 0

                    end tell
                end repeat
                set track_number to 1
            end if
        end repeat

        if is_playing is true then
            set played count of track track_number to 1
            tell application "iTunes"
                stop
            end tell
        else
            play track track_number with once
        end if

    end tell

end tell
0

精彩评论

暂无评论...
验证码 换一张
取 消