我对编码的了解有限。我正在尝试使用applescript和Keynote自动化将PPT转换为HTML的过程。在这个page中,我发现了以下非工作的苹果脚本:
-- 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 :(得分:0)
你违反了Applecript的基本规则之一。避免将tell块放入tell块中。在你的情况下,你把一个Finder告诉代码块放在Keynote tell代码块中。这可能会导致冲突,从而导致错误。我认为这是你的问题。
尝试使用tell块分隔...
-- 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