【问题标题】:AppleScript: ADDING file or folder permissions through Shell scriptAppleScript:通过 Shell 脚本添加文件或文件夹权限
【发布时间】:2014-01-05 02:44:31
【问题描述】:

我只是无法理解这个:( 我想将用户(例如 Joe Smith)添加到一个(或多个)文件夹的权限中。我用以下代码创建了一个小程序:

on open thisStuff
try
    tell application "Finder"
        repeat with this_item in thisStuff
            set thisObj to POSIX path of (alias this_item)
            set scrpt to quoted form of ("chmod -a \"joesmith:allow:read\"")
            do shell script scrpt & " " & thisObj with administrator privileges
        end repeat
    end tell
on error errStr number errorNumber
    error errStr number errorNumber
end try
end open

当我将文件夹放到小程序上时,出现“找不到命令”错误。

如果我进入终端中的正确目录并输入:

chmod +a "joesmith:allow:read" my folder

它可以正常工作。 我猜我的转义或我的 shell 脚本的其他语法有问题,但我就是看不到它:( 任何人都可以请我直接在这里...

编辑……

仍然在破解它!我试过这样:

on open thisStuff
set pass to "mySecretPassword"
try
    tell application "Finder"
        repeat with this_item in thisStuff
            set thisObj to POSIX path of (alias this_item)
            do shell script "sudo chmod -a " & "access_bpf:allow:read " & quoted form of thisObj password pass with administrator privileges
        end repeat
    end tell
on error errStr number errorNumber
    error errStr number errorNumber
end try
end open

...这次我得到了错误:

chmod: No ACL present 'Volumes/Path/to/my/folder/'

Mmmmmmmm……我想不通!

再次感谢您的帮助:)

【问题讨论】:

    标签: shell applescript


    【解决方案1】:

    第一次尝试,如果我将 {choose folder} 发送到打开的处理程序,这对我有用:

    on open thisStuff
        --try
        tell application "Finder"
            repeat with this_item in thisStuff
                set thisObj to POSIX path of (this_item)
                set scrpt to ("/bin/chmod +a \"joesmith allow read\" " & quoted form of thisObj)
                do shell script scrpt with administrator privileges
            end repeat
        end tell
        --on error errstr number errorNumber
        --error errstr number errorNumber
        --end try
    end open
    

    在分配 scrpt 变量的行中有一个无关的“引用形式”。不确定你的 chmod +a 模式字符串中的冒号,但我把它们去掉了,因为我在手册页描述中没有看到那种形式。此外,您在不同时间使用了“-a”和“+a”; +a 是正确的形式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      • 2014-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多