2014-01-28 65 views
0

我一直在爲我妹妹做一個簡單的腳本,但它不起作用。它要求一個整數?我沒有在我的程序中指定它,但無論如何它都會調用它...?AppleScript錯誤 - 整數?

我的腳本:

 activate 
    display dialog "Click Start to start importing your own kindle books!" with title "Kindle Book Uploader by Jeremy Zhang" buttons 
{"Cancel", "Start"} default button "Start" 

    property documentFolder : "documents" 

    tell application "Finder" to (get name of every disk whose ejectable is true) 
    try 
    set kindleLocation to ¬ 
      ((choose from list result with prompt "Select your Kindle from the list:") as text) 
    end try 

    try 
     set bookFiles to ¬ 
      ((choose file with prompt ¬ 
        "Select kindle files to import:" of type {"public.html", "public.rtf", "com.microsoft.word.doc", 
"public.data.mobi", "public.plain-text", "com.adobe.pdf"} with 
multiple selections allowed) as text) 
    end try 

    display dialog "Please wait while the application copies the kindle books..." with title "Kindle Book Uploader by Jeremy Zhang" 

    tell application "Finder" 
     if not (exists folder documentFolder of kindleLocation) then 
     make new folder at kindleLocation with properties {name:documentFolder} 
     end if 
    end tell 

    set fullKindlePath to POSIX path of (kindleLocation as alias) & "documents" 

    tell application "Finder" 
     move (bookFiles) to fullKindlePath 
    end tell 

    display dialog "Process has been done! Please eject your kindle and the files will be on the home screen of your Kindle." with title 
"Kindle Book Uploader by Jeremy Zhang" 

而且從運行它的結果:

 tell current application 
     activate 
    end tell 
    tell application "AppleScript Editor" 
     display dialog "Click Start to start importing your own kindle books!" with title "Kindle Book Uploader by Jeremy Zhang" buttons 
{"Cancel", "Start"} default button "Start" 
     -- {button returned:"Start"} 
    end tell 
    tell application "Finder" 
     get name of every disk whose ejectable = true 
     -- {"JEREMY DISK"} 
    end tell 
    tell application "AppleScript Editor" 
     choose from list {"JEREMY DISK"} with prompt "Select your Kindle from the list:" 
     -- {"JEREMY DISK"} 
     choose file with prompt "Select kindle files to import:" of type {"public.html", "public.rtf", "com.microsoft.word.doc", 
"public.data.mobi", "public.plain-text", "com.adobe.pdf"} with 
multiple selections allowed 
     -- {alias "Macintosh HD:Users:JeremyZhang:Downloads:5 ETS SAT S.pdf"} 
     display dialog "Please wait while the application copies the kindle books..." with title "Kindle Book Uploader by Jeremy Zhang" 
     -- {button returned:"OK"} 
    Result: 
    error "Canât make \"documents\" into type integer." number -1700 from "documents" to integer 

我在做什麼錯?你能糾正我嗎? AppleScript編輯器V:2.5(138) AppleScript 2.2.3

回答

1

這是一個有點誤導性的錯誤。它告訴你documentFolder是錯誤的類型。但是劇本也有其他一些問題。這個版本應該工作 - 看到評論,但嘗試按原樣運行(我刪除了你使用的選項 - 返回繼續字符;我懷疑它在這個論壇上翻譯不好):

activate 
display dialog "Click Start to start importing your own kindle books!" with title "Kindle Book Uploader by Jeremy Zhang" buttons {"Cancel", "Start"} default button "Start" 

property documentFolder : "documents" 

tell application "Finder" to (get name of every disk whose ejectable is true) 
try 
    set kindleLocation to ((choose from list result with prompt "Select your Kindle from the list:") as text) 
    --display dialog class of kindleLocation -- class is text 
end try 

try 
    set bookFiles to ((choose file with prompt "Select kindle files to import:" of type {"public.html", "public.rtf", "com.microsoft.word.doc", "public.data.mobi", "public.plain-text", "com.adobe.pdf"} with multiple selections allowed) as text) 
end try 

display dialog "Please wait while the application copies the kindle books..." with title "Kindle Book Uploader by Jeremy Zhang" 

tell application "Finder" 
    --coerce kindleLocation to alias 
    if not (exists folder documentFolder of alias kindleLocation) then 
     make new folder at kindleLocation with properties {name:documentFolder} 
    end if 
end tell 
--don't use posix ... but you already have variables to build this 
--set fullKindlePath to (kindleLocation) & ":documents:"--could've done this, but you don't need this, you can use same construction as above 

tell application "Finder" 
    move (bookFiles) to folder documentFolder of alias kindleLocation 
end tell 

display dialog "Process has been done! Please eject your kindle and the files will be on the home screen of your Kindle." with title "Kindle Book Uploader by Jeremy Zhang"