2013-12-11 46 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