首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Applescript中的错误-10004和错误-10000是什么?

Applescript中的错误-10004和错误-10000是什么?
EN

Stack Overflow用户
提问于 2012-02-09 01:44:41
回答 2查看 8.9K关注 0票数 3

我有一个在我的计算机上工作的Applescript,但不在我同事的计算机上。我在操作路径时遇到了两个错误:-10004-10000。我有一个关于如何解决这个问题的想法,但是首先我想了解这些错误代码。

下面是脚本(我删除了无用的部分,完整的版本在github上):

代码语言:javascript
复制
-- export all layers to image files

-- Settings
property exportFileExtension : "png"
property ADD_CANVAS_NUMBER : true
-- End of Settings

on file_exists(FileOrFolderToCheckString)
   try
       alias FileOrFolderToCheckString
       return true
   on error
       return false
   end try
end file_exists

tell application "OmniGraffle Professional 5"
    set theWindow to front window
    set theDocument to document of theWindow
    set theFilename to name of theDocument
    -- remove .graffle
    -- FIRST ERROR IS HERE -10004
    set theFilename to text 1 thru ((offset of "." in theFilename) - 1) of theFilename

    set export_folder to (choose folder with prompt "Pick the destination folder") as string
    set export_folder to export_folder & theFilename & ":"

    -- create folder
    if file_exists(export_folder) of me then
        try
            display alert "The file already exists. Do you want to replace it?" buttons {"Cancel", "Erase"} cancel button 1
        on error errText number errNum
            if (errNum is equal to -128) then
                return
            end if
        end try

        -- deletes the folder (necessary because some layers may have been renamed
        do shell script "rm -rf " & quoted form of POSIX path of export_folder

    else
        -- creates the folder
        do shell script "mkdir -p " & quoted form of POSIX path of export_folder
    end if

    set canvasCount to count of canvases of theDocument

    set i to 0
    repeat with canvasNumber from 1 to canvasCount
        set theCanvas to canvas canvasNumber of theDocument
        set canvas_name to name of theCanvas
        set canvas of theWindow to theCanvas
        set layerCount to count of layers of theCanvas

        -- ...

        set area type of current export settings to current canvas
        set draws background of current export settings to false
        set include border of current export settings to false

        set canvas_filename to ""
        -- ...
        set canvas_filename to canvas_filename & canvas_name

        repeat with layerNumber from 1 to layerCount
            set theLayer to layer layerNumber of theCanvas

            if (theLayer is prints) and (class of theLayer is not shared layer) then
                set layer_name to name of theLayer as string
                set filename to canvas_filename & " - " & layer_name & "." & exportFileExtension
                set export_filename to export_folder & filename

                -- show the layer, export, then hide the layer
                if character 1 of layer_name is not "*" then
                    set visible of theLayer to true
                    -- SECOND ERROR IS HERE -1000
                    save theDocument in export_filename
                    set visible of theLayer to false
                end if

            end if

        end repeat

    end repeat
end tell

这是日志:

代码语言:javascript
复制
tell application "OmniGraffle Professional 5"
   get window 1
       --> window id 5032
   get document of window id 5032
       --> document "MSD.graffle"
   get name of document "MSD.graffle"
       --> "MSD.graffle"
   offset of "." in "MSD.graffle"
       --> error number -10004
end tell
tell current application
   offset of "." in "MSD.graffle"
       --> 4
end tell
tell application "OmniGraffle Professional 5"
   choose folder with prompt "Pick the destination folder"
       --> alias "Macintosh HD:Users:Romain:Desktop:Temp:"
   display alert "The file already exists. Do you want to replace it?" buttons {"Cancel", "Erase"} cancel button 1
       --> {button returned:"Erase"}
   do shell script "rm -rf '/Users/Romain/Desktop/Temp/MSD/'"
       --> error number -10004
end tell
tell current application
   do shell script "rm -rf '/Users/Romain/Desktop/Temp/MSD/'"
       --> ""
end tell
tell application "OmniGraffle Professional 5"
...
...
   save document "MSD.graffle" in "Macintosh HD:Users:Romain:Desktop:Temp:MSD:1- Navigation - 1Layout.png"
       --> error number -10000
Result:
error "OmniGraffle Professional 5 got an error: AppleEvent handler failed." number -10000

谢谢!

我更新了脚本,但仍然得到了错误-10000。以下是修改后的行:

代码语言:javascript
复制
save theDocument in file exportFilename

代码语言:javascript
复制
-- Create folder if does not exist, remove it otherwise
-- Shell script should not be executed inside tell application block
if file_exists(export_folder) of me then
    try
        display alert "The file already exists. Do you want to replace it?" buttons {"Cancel", "Erase"} cancel button 1
    on error errText number errNum
        if (errNum is equal to -128) then
            return
        end if
    end try

    tell me
        -- Delete the folder
        do shell script "rm -rf " & quoted form of POSIX path of export_folder
    end tell

else
    tell me
        -- Create the folder
        do shell script "mkdir -p " & quoted form of POSIX path of export_folder
    end tell
end if
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-09 09:01:31

错误-10000 - -10015是事件注册表错误。

错误-10000本身并不是一个目标错误,因为在大多数情况下,它会抛出an -1708。大多数情况下,这不是一个目标错误,而是一个不完整的命令或错误的使用括号。如果你用:

代码语言:javascript
复制
save theDocument in file export_filename

error -10004是一个违反权限的错误,这意味着您正在处理不允许的文件。可能不允许您删除文件并执行shell脚本命令,应该始终在tell应用程序块之外使用。问题是目标应用程序可以作为脚本以外的另一个用户运行。我并不是说是错误,但有可能这就是问题所在。否则,您只需获得足够的权限,并且需要向用户询问管理员权限。

代码语言:javascript
复制
do shell script "do something" with administrator privileges.
票数 6
EN

Stack Overflow用户

发布于 2012-02-09 02:40:03

我还没有找到这些错误代码被记录的地方,但它们主要处理的是目标应用程序无法处理的事件。前两个错误- -10004来自在一个应用程序tell语句(偏移量do shell脚本)中使用一个标准添加命令--应用程序不知道这些命令是什么,将错误传递到AppleScript,但是AppleScript知道它们是什么,并执行它们。

我没有OmniGraffle,但最后一个错误是告诉您保存命令无法执行,这可能是由于目标不是文件说明符的问题--它只是一个文本字符串,因此您可能不得不将其强制放入命令想要的东西中。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9204320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档