监测的AppleScript Spotify的曲目变化? [英] Monitoring Spotify track change in Applescript?

查看:141
本文介绍了监测的AppleScript Spotify的曲目变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出通过Spotify的AppleScript的库来检测轨道变化的最佳途径。到目前为止,我已经试过检查球员的位置 - 如果它等于0,则是一个新的轨道,低吼​​通知再次出现。 (如果有人开始一首歌曲结束后,等这并不主要工作。)

I'm trying to figure out the best way via Spotify's Applescript library to detect a track change. So far, I've tried checking player position -- if it equals 0 it is a new track and the Growl notification appears again. (This didn't work mostly if someone started a song over, etc.)

我不知道是否该更合理的方法是有一个运行iTunes的闲置脚本和改变检查当前曲目的名称每隔几秒钟。我担心这可能是一个有点猪记忆明智的。我不能让这个code要么工作。

I'm wondering if the more plausible method is having an idle iTunes script running and checking the current track name for change every couple seconds. I'm worried this might be a bit of a hog memory-wise. I can't get this code to function either.

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

这可能有点复杂,但任何帮助是AP preciated。

This might be a little complicated but any help is appreciated.

推荐答案

值得一提的,这是无关紧要的。

Worth mentioning this is irrelevant as Spotify has patched this in a recent update.

这篇关于监测的AppleScript Spotify的曲目变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆