什么是错误-10004和错误-10000 AppleScript中 [英] What are error -10004 and error -10000 in Applescript

查看:864
本文介绍了什么是错误-10004和错误-10000 AppleScript中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有工作在我的电脑上的AppleScript,但不能在我的同事的。操纵路径时,我得到两个错误: -10004 -10000 。我有一个<一个href=\"http://stackoverflow.com/questions/9203985/how-to-get-filename-without-extension-from-omnigraffle\">idea如何解决这个问题,但首先我想了解这些错误codeS。

下面是脚本(我删除无用的部分,完整版的<一个href=\"https://github.com/charlax/OmnigraffleScripts/blob/master/ExportAllLayers/ExportAllLayers.applescript\"相对=nofollow> github上):

   - 所有层导出为图像文件 - 设置
物业exportFileExtension:PNG
物业ADD_CANVAS_NUMBER:真
- 设置结束在file_exists(FileOrFolderToCheckString)
   尝试
       别名FileOrFolderToCheckString
       返回true
   出错
       返回false
   年底试
结束file_exists告诉应用程序OmniGraffle专业5
    设置theWindow到前窗
    设置theDocument为theWindow文件
    设置theFilename为theDocument的名字
     - 删除.graffle
     - 第一个错误是这里-10004
    设置theFilename文本1至((在theFilename偏移。) - 1)theFilename的    集export_folder到(选择文件夹提示选择目标文件夹)作为字符串
    设置export_folder为export_folder&安培; theFilename&安培; :     - 创建文件夹
    如果我的file_exists(export_folder),然后
        尝试
            显示警报的文件已经存在。是否要替换它?按钮{取消,删除}取消按钮1
        在错误errText号差错编号
            如果(差错编号等于-128),那么
                返回
            万一
        年底试         - 因为某些层可能已被重命名删除必要的文件夹(
        做shell脚本室射频与&amp; export_folder的POSIX路径引号形式    其他
         - 创建该文件夹
        做shell脚本的mkdir -p&放大器; export_folder的POSIX路径引号形式
    万一    设置canvasCount算theDocument的画布    我设置为0
    与canvasNumber从1到canvasCount重复
        设置theCanvas以帆布theDocument的canvasNumber
        设置canvas_name为theCanvas的名字
        设置为theCanvas theWindow帆布
        设置layerCount算theCanvas的层         - ...        当前导出设置到当前画布设置区域类型
        集绘制的电流输出设置为false背景
        一套包括目前的出口设置为false边界        设置canvas_filename为
         - ...
        设置canvas_filename为canvas_filename&安培; canvas_name        与layerNumber从1到layerCount重复
            设置theLayer到层theCanvas的layerNumber            如果(theLayer是版画)和(类theLayer的不共享层),然后
                设置为LAYER_NAME的theLayer名字符串
                设置文件名canvas_filename&安培; - 与&amp; LAYER_NAME&安培; 。 &安培; exportFileExtension
                设置export_filename为export_folder&安培;文件名                 - 显示层,出口,然后隐藏层
                如果LAYER_NAME的性格1不是*,则
                    theLayer的设置可见真
                     - 第二个错误HERE -1000
                    保存在theDocument export_filename
                    theLayer的设置可见为false
                万一            万一        重复结束    重复结束
告诉结束

下面是日志:

 告诉应用程序OmniGraffle专业5
   获得窗口1
        - &GT;窗口ID 5032
   获取窗口ID 5032的文档
        - &GT;文档MSD.graffle
   得到的文件名MSD.graffle
        - &GT; MSD.graffle
   偏移。在MSD.graffle
        - &GT;错误号-10004
告诉结束
告诉当前的应用程序
   偏移。在MSD.graffle
        - &GT; 4
告诉结束
告诉应用程序OmniGraffle专业5
   选择带有提示的文件夹选择目标文件夹
        - &GT;别名的Macintosh HD:用户:罗曼:桌面:温度:
   显示警报的文件已经存在。是否要替换它?按钮{取消,删除}取消按钮1
        - &GT; {按钮返回:清除}
   做shell脚本室射频'/用户/罗曼/桌面/温度/ MSD /'
        - &GT;错误号-10004
告诉结束
告诉当前的应用程序
   做shell脚本室射频'/用户/罗曼/桌面/温度/ MSD /'
        - &GT;
告诉结束
告诉应用程序OmniGraffle专业5
...
...
   保存文件MSD.graffle中的Macintosh HD:用户:罗曼:桌面:温度:MSD:1 - 导航 - 1Layout.png
        - &GT;错误号-10000
结果:
错误OmniGraffle专业5得到了一个错误:的AppleEvent处理程序失败。数-10000

谢谢!


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

 文件exportFilename保存theDocument

   - 创建文件夹,如果不存在,否则将其删除
- shell脚本应该不会告诉应用程序块里面执行
如果我的file_exists(export_folder),然后
    尝试
        显示警报的文件已经存在。是否要替换它?按钮{取消,删除}取消按钮1
    在错误errText号差错编号
        如果(差错编号等于-128),那么
            返回
        万一
    年底试    告诉我
         - 删除文件夹
        做shell脚本室射频与&amp; export_folder的POSIX路径引号形式
    告诉结束其他
    告诉我
         - 创建文件夹
        做shell脚本的mkdir -p&放大器; export_folder的POSIX路径引号形式
    告诉结束
万一


解决方案

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

错误-10000本身并不是目标错误,因为它会引发在这些情况下的-1708居多。大部分时间它不是一个目标错误,但命令的不完整或括号错误使用。如果你使用的是什么:

 文件export_filename保存theDocument

错误-10004是一种特权违规错误,这意味着你正在做的事情与不允许的文件。也许你不能删除该文件,然后执行shell脚本命令,一定要使用外告诉应用程序块。问题是,在目标应用程序可以作为另一个用户不是脚本运行。我不是说这是错误,但有一个机会,它这就是问题所在。否则,你根本HEVE没有足够的特权,你需要问管理员权限的用户。

 做外壳脚本做什么具有管理员权限。

I have an Applescript that is working on my computer, but not on my colleague's. I get two errors when manipulating paths: -10004 and -10000. I have an idea on how to solve this, but first I'd like to understand those error codes.

Here is the script (I removed useless part, the full version is on github):

-- 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

Here is the log:

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

Thanks!


I updated the script but I still get error -10000. Here are the modified lines:

save theDocument in file exportFilename

and

-- 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

解决方案

Errors -10000 - -10015 are event registry errors.

Error -10000 is not a target error per se, because it will throw an -1708 in those cases mostly. most of the time it is not a target error but an incomplete command or wrong usage of brackets. What if you use:

save theDocument in file export_filename

Error -10004 is a privilege violation error, which mean you're doing something with the file that isn't allowed. Probably you're not allowed to remove the file and do shell script command should always be used outside tell application blocks. The problem is that the target application can run as another user than the script. I'm not saying it is the error but there is a chance that it this is the problem. Otherwise you simply heve not enough privileges and you need to ask the user for administrator privileges.

do shell script "do something" with administrator privileges.

这篇关于什么是错误-10004和错误-10000 AppleScript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆