【问题标题】:Applescript to change rating of song currently playing in iTunesApplescript 更改当前在 iTunes 中播放的歌曲的评级
【发布时间】:2011-08-28 07:15:36
【问题描述】:

我设置了一个 applescript 来更改 iTunes 中当前歌曲的评分,它在前几次有效,但现在什么也没做。代码如下:

tell application "System Events"
    if (name of processes) contains "iTunes" then
        set iTunesRunning to true
    else
        set iTunesRunning to false
    end if
end tell

if iTunesRunning then
    tell application "iTunes"
        repeat with theTrack in (get selection)
            set the rating of theTrack to 100
        end repeat
    end tell
end if

有人发现其中有什么明显的问题吗?仅供参考,这是附加到全局热键的,但即使在 Applescript 编辑器中打开它并点击“运行”也无济于事。

【问题讨论】:

    标签: applescript itunes


    【解决方案1】:

    确认。我所要做的就是要求自己找到答案。

    tell application "System Events"
        if (name of processes) contains "iTunes" then
            set iTunesRunning to true
        else
            set iTunesRunning to false
        end if
    end tell
    
    if iTunesRunning then
        tell application "iTunes"
            set rating of current track to 100
        end tell
    end if
    

    【讨论】:

      【解决方案2】:

      我不记得我在哪里找到的,但它是一个更强大的版本,可能会对您有所帮助。我使用FastScripts 使用键盘命令执行它。它会弹出一个对话框,提示您以 0 到 5 的等级对当前歌曲进行评分,默认评分为 4。

      tell application "Finder"
          set frontApp to name of first process whose frontmost is true
      end tell
      set currTrack to ""
      set thisNum to false
      tell application "iTunes"
          if player state = playing then
              set currTrack to current track
              set thisName to name of current track
              set thisArt to artist of current track
              set numList to {"0", "1", "2", "3", "4", "5", "", "Rate All"}
              set thisRating to rating of currTrack
              set songArt to ("'" & thisName & "' by " & thisArt)
          end if
      end tell
      tell application frontApp
          if currTrack = "" then
              beep
              tell application frontApp
                  display dialog "There is no song playing in iTunes at this time." buttons "OOPS" default button "OOPS" with icon note
              end tell
          else
              if thisRating ≠ 0 then
                  set thisRating to 4
                  set thisList to (choose from list numList with prompt "Select a rating for this song:" & return & songArt & return & "Select \"Rate All\" to apply rating to all matching songs." default items thisRating OK button name "Select" with empty selection allowed and multiple selections allowed)
              else
                  set thisList to (choose from list numList with prompt "Select a rating for this song:" & return & songArt & return & "Select \"Rate All\" to apply rating to all matching songs." OK button name "Select" with empty selection allowed and multiple selections allowed)
              end if
          end if
      end tell
      
      if thisList ≠ false then
          --tell application "iTunes"
          set thisRating to ""
          repeat with i from 1 to count of items of thisList
              set thisItem to item i of thisList
              if thisItem = "Rate All" then
                  if thisRating = "" then
                      display dialog "You must select a rating to apply to this song." buttons "OK" default button "OK" with icon caution
                  else
                      tell application "iTunes"
                          set dataList to {name, artist, album, time} of currTrack
                          set addSourceData to {time, size, year, bit rate} of currTrack
                          set matchList to {"Time", "Size", "Year", "Bit Rate"}
                          set matchDef to (choose from list matchList with prompt "You may choose criteria to match in addition to track name, artist, and album." with multiple selections allowed and empty selection allowed)
                          if matchDef = {} then set matchDef to false
                          set trackList to (every track of library playlist 1 whose ((name = item 1 of dataList) and (artist = item 2 of dataList) and (album = item 3 of dataList)))
                          set trackCount to count of items of trackList
                          repeat with j from 1 to trackCount
                              set thisTrack to item j of trackList
                              set notMatch to false
                              if matchDef ≠ false then
                                  set addSynchData to {time, size, year, bit rate} of thisTrack
                                  repeat with m from 1 to 4
                                      if ((m = 1) and (matchDef contains "Time")) or ((m = 2) and (matchDef contains "Size")) or ((m = 3) and (matchDef contains "Year")) or ((m = 4) and (matchDef contains "Bitrate")) then
                                          if item m of addSourceData ≠ item m of addSynchData then
                                              set notMatch to true
                                              exit repeat
                                          end if
                                      end if
                                  end repeat
                              end if
                              if notMatch = false then
                                  set rating of thisTrack to thisRating
                              end if
                          end repeat
                          if thisRating > 0 then
                              set thisRating to thisRating / 20 as integer
                          end if
                      end tell
                      display dialog "Rating of " & thisRating & " applied to " & trackCount & " song(s)." buttons "OK" default button "OK" giving up after 3
                  end if
              else
                  set thisRating to thisItem * 20
                  tell application "iTunes"
                      set rating of currTrack to thisRating
                  end tell
              end if
          end repeat
          --end tell
      end if
      

      【讨论】:

        猜你喜欢
        • 2011-05-02
        • 1970-01-01
        • 2023-03-08
        • 1970-01-01
        • 1970-01-01
        • 2023-03-25
        • 1970-01-01
        • 2016-03-27
        • 1970-01-01
        相关资源
        最近更新 更多