2014-09-26 77 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」,因爲那樣您就可以執行諸如說「在照片中重複使用照片」之類的內容。「