2011-07-12 46 views
1

我有一个applescript,我要求一首歌来设置播放计数,另一个来设置最后播放的日期。这些从perl脚本中调用,从last.fm中获取数据。不幸的是,每当我打电话给最后播放的日期脚本时,我收到一条错误消息setItunesLastPlayed.scpt: execution error: iTunes got an error: A descriptor type mismatch occurred. (-10001)Applescript,iTunes和'date'

我打电话这样说:

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 

任何人都可以指出我的修复?

+0

该错误是非常通用的。你的游戏计数脚本是否有效?您是否曾尝试从脚本编辑器或脚本调试器运行Applescript,并确切地查看它失败的位置? –

+0

@Philip Regan play count脚本工作正确,因为它只是传入一个数字。当我在编辑器中运行日期脚本时,使用硬编码的“字符串”(“set theLastPlay to date”,2011年7月5日星期三上午07:14:11“')它正常工作。 –

+0

我在这里阅读这篇文章之前发布了一条评论,但是我想知道当字符串从perl传递到Applescript时是否会进行某种转换,导致字符串在创建日期对象时不再可解析。 –

回答

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(或者他们依赖存储和报告日期的技术)决定更改日期格式。

+0

这不就是'设置LastPlay到最后的播放'应该做什么? –

+0

不一定。 Applescript是动态类型的错误,所以当它不能解析日期时,它可能会尝试设置字符串本身并返回错误,但确切的行为是不知道的(至少对我和我来说还没有看到文件,否则告诉我)。当我明确地将字符串转换为日期并设置日期时,我可以毫无错误地设置日期。 –