AppleScript:通过Shell脚本添加文件或文件夹权限

时间:2014-01-05 02:44:31

标签: shell applescript

我只是无法绕过这一个:( 我想将一个用户(比如Joe Smith)添加到一个(或几个)文件夹的权限中。我使用以下代码创建了一个applet:

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

当我在applet上删除一个文件夹时,出现“找不到命令”错误。

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

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

它没有问题。 我想我的unescaping或我的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/'

嗯......我无法想象!!

再次感谢您的帮助:)

1 个答案:

答案 0 :(得分:0)

第一次尝试,如果我将{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是正确的形式。