【问题标题】:Apple Script: How do I get a reference to the next track in iTunes?Apple Script:如何在 iTunes 中获取对下一首曲目的引用?
【发布时间】:2011-09-14 10:43:55
【问题描述】:

我想要实现的是:

tell application "iTunes"
    play next track with once
end tell

当然,“下一个曲目”是一个命令,而不是对下一个曲目的引用 - 所以这不起作用。我已经阅读了文档并且真的被困在这一点上 - 我将如何编写代码以使其正常工作?

如果解决方案涉及制作播放列表或其他任何东西 - 我只需要一个播放下一首歌曲然后停止的脚本。

-

非常感谢任何帮助 :) 我已经浪费了很多时间来尝试让它工作!

【问题讨论】:

    标签: applescript itunes


    【解决方案1】:

    这个脚本很hacky,但它可以工作......

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

    【讨论】:

    • 谢谢!这几乎可以做到......唯一的问题是它在iTunes停止曲目后不起作用(说无法获得当前曲目) - 我有点需要它这样做:)知道如何解决这个问题?
    • @thanks 但它和以前有同样的问题。不过,我设法找到了解决方案:)
    【解决方案2】:

    经过一番折腾,这就是我的做法。如果您能看到更好的方法,那么我想知道!

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-24
      • 2011-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多