Applescript для изменения рейтинга песни, которая в данный момент воспроизводится в iTunes - PullRequest
4 голосов
/ 18 мая 2011

Я настроил яблочный скрипт для изменения рейтинга текущей песни в 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 и нажатие клавиши «Выполнить» ничего не делает.

Ответы [ 2 ]

7 голосов
/ 18 мая 2011

Ack.Все, что мне нужно было, это попросить найти ответ сам.

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
0 голосов
/ 20 мая 2011

Я не помню, где я нашел это, но это более надежная версия, которая может вам помочь.Я выполняю его с помощью ключевой команды, используя 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
...