2014-09-26 76 views
0

我想从一批图像的图像日期和图像日期粘贴到另一个批次使用相同的文件名(但不同的文件类型)AppleScript的错误:-1728在创建日期对象

图像我发现一个AppleScript可以帮助我:http://brettgrossphotography.com/2008/12/10/aperture-applescript-export-restore-metadata

但是,日期部分是棘手的。

在导出部分中,我通常解析出日期,但导入部分不起作用。

 if (curTagShort is "ImageDate") then 
      log "-- try to set the date --" 
      -- set curDate to (curVal as date) 
      set curDate to rich text of (item ctr of theList) 
      log (curVal as string) 
      adjust image date (date curVal as string) of images {curImg} 
     else 

以上代码生成以下日志:

(*-- try to set the date --*) 
(*Freitag, 26. September 2014 20:21:21*) 
get date "Freitag, 26. September 2014 20:21:21" of image version id "CeT8CoCwSYuhejftq9kmag" 
    --> error number -1728 from date "Freitag, 26. September 2014 20:21:21" of image version id "CeT8CoCwSYuhejftq9kmag" 
(*date "Freitag, 26. September 2014 20:21:21" of item 1 of {«class rkdp» id "CeT8CoCwSYuhejftq9kmag" of application "Aperture"} kann nicht in Typ string umgewandelt werden.*) 

可变CURVAL是

set curVal to item ctr of theList 

CTR是当前索引,的thelist是一个列表...明显。

到目前为止,对于非工作部分,如果用实际字符串“Freitag,2014年9月26日20:21:21”替换>> curVal作为字符串< <,它可以工作。

用我的AppleScript的小知识,我认为这个问题是,“CURVAL”是列表的一部分,因此

"Freitag, 26. September 2014 20:21:21" of item 1 of {«class rkdp» id "CeT8CoCwSYuhejftq9kmag" of application "Aperture"} 

那么,有没有说我缺少一个把戏?

谢谢!

回答

0

不要强制将日期对象转换为字符串。 Date对象有一个名为“date string”的属性,您可以使用它。

而不是做这个的:

date curVal as string 

...这样做:

date string of date curVal 

在你的AppleScript编辑器本身试试这个示例脚本,以明确:

set theDate to the current date 
set theDateString to the date string of theDate 
set theTimeString to the time string of theDate 
set theDateTimeString to theDateString & space & theTimeString 
return theDateTimeString 

在在AppleScript Editor窗口底部的结果窗格中,您将看到此脚本返回当前日期a第二时间为一个字符串,像这样:

"Sunday, September 28, 2014 09:11:36" 

CTR是当前指数的thelist是一个列表...很明显。

如果你必须解释你的变量名称,那么它们被命名的很糟糕。我建议您将“ctr”重命名为“theCurrentIndex”,无论“列表”是否列出,请指定。例如:“thePhotoList”。或者您可以使用复数名称作为您的列表,例如“thePhotos”,因为那样您就可以执行诸如说“在照片中重复使用照片”之类的内容。“