2015-02-17 36 views
0

我的編碼知識是有限的。我正在嘗試使用applescript和Keynote將PPT轉換爲HTML的過程自動化。在這種page我發現下面的非工作的蘋果腳本:Applescript - 批量轉換PPT到HTML

-- THE DESTINATION FOLDER 
-- (see the "path" to command in the Standard Additions dictionary for other locations, such as pictures folder, movies folder, sites folder, desktop folder) 
set the defaultDestinationFolder to (path to documents folder) 

tell application "Keynote" 
activate 
try 
    if playing is true then tell the front document to stop 

    if not (exists document 1) then error number -128 

    -- DERIVE NAME FOR NEW FOLDER FROM NAME OF THE FRONT DOCUMENT 
    set documentName to the name of the front document 
    if documentName ends with ".key" then ¬ 
     set documentName to text 1 thru -5 of documentName 

    -- CREATE AN EXPORT DESTINATION FOLDER 
    -- IMPORTANT: IT’S ADVISED TO ALWAYS CREATE A NEW DESTINATION FOLDER, AS THE CONTENTS OF ANY TARGETED FOLDER WILL BE OVERWRITTEN 
    tell application "Finder" 
     set newFolderName to documentName 
     set incrementIndex to 1 
     repeat until not (exists folder newFolderName of defaultDestinationFolder) 
      set newFolderName to documentName & "-" & (incrementIndex as string) 
      set incrementIndex to incrementIndex + 1 
     end repeat 
     set the targetFolder to ¬ 
      make new folder at defaultDestinationFolder with properties ¬ 
       {name:newFolderName} 
     set the targetFolderHFSPath to targetFolder as string 
    end tell 

    -- EXPORT THE DOCUMENT 
    with timeout of 1200 seconds 
     export front document as HTML to file targetFolderHFSPath 
    end timeout 

    on error errorMessage number errorNumber 
    display alert "EXPORT PROBLEM" message errorMessage 
    error number -128 
    end try 
    end tell 

    -- OPEN THE DESTINATION FOLDER 
    tell application "Finder" 
open the targetFolder 
end tell 

-- VIEW THE PRESENTATION 
tell application "Safari" 
activate 
open file (targetFolderHFSPath & "index.html") 
end tell 

我正在尋找一種方式來解決這個問題。目前,我得到以下結果:

error "Keynote got an error: No user interaction allowed." number -1713 

回答

0

你破壞了蘋果的基本規則之一。避免將告訴塊放在告訴塊內。在你的情況下,你把一個Finder告訴塊代碼在Keynote中。這可能會導致衝突,從而導致錯誤。我認爲這是你的問題。

嘗試對分離告訴塊...

-- THE DESTINATION FOLDER 
-- (see the "path" to command in the Standard Additions dictionary for other locations, such as pictures folder, movies folder, sites folder, desktop folder) 
set the defaultDestinationFolder to (path to documents folder) 


try 
    tell application "Keynote" 
     activate 
     if playing is true then tell the front document to stop 

     if not (exists document 1) then error number -128 

     -- DERIVE NAME FOR NEW FOLDER FROM NAME OF THE FRONT DOCUMENT 
     set documentName to the name of the front document 
     if documentName ends with ".key" then ¬ 
      set documentName to text 1 thru -5 of documentName 

     -- CREATE AN EXPORT DESTINATION FOLDER 
     -- IMPORTANT: IT’S ADVISED TO ALWAYS CREATE A NEW DESTINATION FOLDER, AS THE CONTENTS OF ANY TARGETED FOLDER WILL BE OVERWRITTEN 
    end tell 

    tell application "Finder" 
     set newFolderName to documentName 
     set incrementIndex to 1 
     repeat until not (exists folder newFolderName of defaultDestinationFolder) 
      set newFolderName to documentName & "-" & (incrementIndex as string) 
      set incrementIndex to incrementIndex + 1 
     end repeat 
     set the targetFolder to ¬ 
      make new folder at defaultDestinationFolder with properties ¬ 
       {name:newFolderName} 
     set the targetFolderHFSPath to targetFolder as string 
    end tell 

    -- EXPORT THE DOCUMENT 
    with timeout of 1200 seconds 
     tell application "Keynote" 
      export front document as HTML to file targetFolderHFSPath 
     end tell 
    end timeout 

on error errorMessage number errorNumber 
    display alert "EXPORT PROBLEM" message errorMessage 
    error number -128 
end try 

-- OPEN THE DESTINATION FOLDER 
tell application "Finder" 
    open the targetFolder 
end tell 

-- VIEW THE PRESENTATION 
tell application "Safari" 
    activate 
    open file (targetFolderHFSPath & "index.html") 
end tell