Applescript,iTunes和'date'

时间:2011-07-12 15:23:22

标签: perl applescript itunes

我有一个苹果脚本,我要求设置一首歌来设置播放次数,另一次用来设置最后一次播放的日期。这些是从从last.fm获取数据的perl脚本调用的。不幸的是,每当我调用上次播放的日期脚本时,都会收到错误消息setItunesLastPlayed.scpt: execution error: iTunes got an error: A descriptor type mismatch occurred. (-10001)

我这样称呼它:

osascript /Users/gms8994/setItunesLastPlayed.scpt "<ARTIST>" "<TITLE>" "Wednesday, July 05, 2011 07:14:11 AM"

我注意到如果我从itunes请求最后一次播放的值,它会在没有零填充日期和小时的情况下返回,所以我尝试删除它们,但无济于事。

这是我的剧本。

on run argv
    tell application "iTunes"
        set theArtist to (item 1 of argv)
        set theTitle to (item 2 of argv)
        set theLastPlay to (item 3 of argv)

        set theLastPlay to date theLastPlay

        set results to (every file track of playlist "Library" whose artist contains theArtist and name contains theTitle)
        repeat with t in results
            tell t
                say theLastPlay
                set played date of t to theLastPlay
            end tell
        end repeat
    end tell
end run

有人能指出我修复吗?

1 个答案:

答案 0 :(得分:0)

轨道的played date属性需要date个对象,而不仅仅是日期字符串。您需要将日期转换为日期对象:

set newDate to (current date)
set month of newDate to "July"
set year of newDate to "2011"
(* You can fill in the rest *)
set played date of t to newDate

我认为没有办法直接从给定的字符串创建日期对象,因此在last.fm(或他们依赖存储的技术)的情况下,你必须维护一个函数来为你做这件事。并报告日期)决定更改其日期格式。