代码之家  ›  专栏  ›  技术社区  ›  Zax

AppleScript:尝试检索服务器磁盘时出错

  •  0
  • Zax  · 技术社区  · 7 年前

    我正在尝试测试是否安装了服务器(我的NAS)。我不能使用 磁盘名称 因为AppleScript返回NAS卷的名称,而不是NAS的名称,所以我尝试:

    tell application "Finder"
        tell application "System Events" to set theVolumes to every disk
        repeat with thisVolume in theVolumes
            set isLocal to thisVolume's local volume
            if (not isLocal) then
                set thisDisk to thisVolume's server -- > unable to coerce the data to the desired type
            end if
        end repeat
    end tell
    

    脚本调试器返回以下错误: 无法将数据强制为所需类型

    非常感谢。

    1 回复  |  直到 7 年前
        1
  •  0
  •   vadian    7 年前

    代码完全属于 System Events . 查找者根本不参与。

    出现错误的原因是您试图解决 系统事件 a中的术语 Finder 告诉block。代替 查找器 具有 系统事件 并移除 tell 第二行的一部分。

    tell application "System Events"
        set theVolumes to every disk
        repeat with thisVolume in theVolumes
            set isLocal to thisVolume's local volume
            if (not isLocal) then
                set thisDisk to thisVolume's server -- > unable to coerce the data to the desired type
            end if
        end repeat
    end tell