Мониторинг изменения трека Spotify в Applescript?

Я пытаюсь найти лучший способ через библиотеку Spotify Applescript для обнаружения смены трека. Пока что я пробовал проверить позицию игрока - если он равен 0, это новый трек, и снова появляется уведомление Growl. (В основном это не сработало, если кто-то начал песню заново и т. Д.)

Мне интересно, есть ли более правдоподобный метод - запустить скрипт iTunes в режиме ожидания и проверять текущее название трека на предмет изменения каждые пару секунд. Я беспокоюсь, что это может быть немного плохо для памяти. Я тоже не могу заставить этот код работать.

tell application "System Events"
    -- checks for instance of Growl and Spotify, does not run if both programs are not active
    set isRunning to ¬
        (count of (every process whose name is "Growl")) > 0
    (count of (every process whose name is "Spotify")) > 0
end tell

--establish empty variable to be filled by song title later
global latest_song
set latest_song to ""

on idle
    tell application "Spotify"
        if player state is playing then
            copy name of current track to current_tracks_name
            -- runs match between last and current song titles
            if current_tracks_name is not latest_song then
                copy current_tracks_name to latest_song
                set who to artist of current track
                set onwhat to album of current track
                tell application "Growl"
                    -- Make a list of all the notification types 
                    -- that this script will ever send:
                    set the allNotificationsList to ¬
                        {"SpotifyNewTrack"}

                    -- Make a list of the notifications 
                    -- that will be enabled by default.      
                    -- Those not enabled by default can be enabled later 
                    -- in the 'Applications' tab of the growl prefpane.
                    set the enabledNotificationsList to ¬
                        {"SpotifyNewTrack"}

                    -- Register our script with growl.
                    -- You can optionally (as here) set a default icon 
                    -- for this script's notifications.
                    register as application ¬
                        "Spotify" all notifications allNotificationsList ¬
                        default notifications enabledNotificationsList ¬
                        icon of application "Spotify"

                    --  Send a Notification...
                    notify with name ¬
                        "SpotifyNewTrack" title ¬
                        current_tracks_name description ¬
                        who application name "Spotify"
                end tell
            end if
            return 5
        end if
    end tell
end idle

Это может быть немного сложно, но приветствуется любая помощь.

5
задан Hugo 15 January 2012 в 07:59
поделиться