在 Applescript 中监控 Spotify 曲目变化? [英] Monitoring Spotify track change in Applescript?

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

问题描述

我正在尝试通过 Spotify 的 Applescript 库找出检测曲目更改的最佳方法.到目前为止,我已经尝试检查玩家位置——如果它等于 0,则它是一个新轨道,并且再次出现 Growl 通知.(如果有人重新开始歌曲等,这通常不起作用)

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 脚本运行并每隔几秒钟检查当前曲目名称的变化.我担心这可能有点像猪的记忆.我也无法使用此代码.

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

这可能有点复杂,但感谢您的帮助.

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

推荐答案

值得一提的是这无关紧要,因为 Spotify 在最近的更新中对此进行了修补.

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

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

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