2013-12-11 72 views
0

我的腳本通過的AppleScript與iPhoto通信時收到此錯誤,我無法重現的用戶:918:955: execution error: iPhoto got an error: "4.294967323E+9Mahabalipuram" doesn’t understand the 「write」 message. (-1708)神祕AppleScript的錯誤:「4.294967323E + 9Mahabalipuram」不理解「寫」消息

產生錯誤的AppleScript的是:

set nul to character id 0 
set text item delimiters to nul 

set albumsFile to "/Users/[user]/Downloads/blah.blah" 
set fp to open for access (POSIX file albumsFile) with write permission 

tell application "iPhoto" 
    repeat with anAlbum in albums 
     if anAlbum's type is regular album then 
      set albumName to anAlbum's name 
      if albumName is not "Last Import" then 
       set albumPhotoIds to (id of every photo of anAlbum) as Unicode text 
       if length of albumPhotoIds is greater than 0 then 
        set currentAlbum to anAlbum 
        repeat while currentAlbum's parent exists 
         set currentAlbum to currentAlbum's parent 
         set albumName to currentAlbum's name & " > " & albumName 
        end repeat 
        set albumId to anAlbum's id 

        set albumData to {"", albumId, albumName, ""} as Unicode text 
        write albumData to fp as Unicode text 
        write albumPhotoIds to fp as Unicode text 
        write nul to fp as Unicode text 
       end if 
      end if 
     end if 
    end repeat 
end tell 

close access fp 

沒有人有任何想法,這是怎麼回事錯在這裏?在這個Github問題上有更多的背景:https://github.com/jawj/iphoto-flickr/issues/7

回答

1

這可能工作(未經測試);它通常會遇到這種錯誤。但是,正如艾達昂指出的那樣,重構劇本可能是最好的選擇。

tell me to write albumData to fp as Unicode text 
tell me to write albumPhotoIds to fp as Unicode text 
tell me to write nul to fp as Unicode text 

這也很好地說明了如何告訴工作(有時是「幫倒忙」)

+0

謝謝。這確實有效(或者,等同於將三個寫入放在'告訴我'區塊中),並且比@adayzdone更容易修復(加上它不會在每次循環迭代中打開和關閉文件)。我越來越不是AppleScript粉絲。 – jawj

0

寫是從StandardAdditions,而不是iPhoto,所以你不能讓iPhoto寫。這將是沿線的東西:

property nul : character id 0 
set text item delimiters to nul 

set albumsFile to (path to downloads folder as text) & "blah.txt" 

tell application "iPhoto" 
    repeat with anAlbum in albums 
     if anAlbum's type is regular album then 
      set albumName to anAlbum's name 
      if albumName is not "Last Import" then 
       set albumPhotoIds to (id of every photo of anAlbum) 

       if length of albumPhotoIds is greater than 0 then 
        set currentAlbum to anAlbum 
        repeat while currentAlbum's parent exists 
         set currentAlbum to currentAlbum's parent 
         set albumName to currentAlbum's name & " > " & albumName 
        end repeat 
        set albumId to anAlbum's id 
        set albumData to {"", albumId, albumName, ""} as Unicode text 

        my writeIt(albumsFile, albumData, albumPhotoIds) 
       end if 
      end if 
     end if 
    end repeat 
end tell 

on writeIt(albums_File, album_Data, album_PhotoIds) 
    try 
     set fp to open for access albums_File with write permission 
     write album_Data to fp 
     write album_PhotoIds to fp 
     write nul to fp 
     close access fp 
    on error 
     try 
      close access fp 
     end try 
    end try 
end writeIt 
+0

感謝這個,我去看看是否有幫助。奇怪的是,我在爲我和其他許多用戶工作之前就擁有它。 – jawj