permissions - 无法更改 AppleScript 中文件夹的权限根目录
问题描述
我是 AppleScript 的新手,我尝试制作 droplet 以递归方式更改对删除的文件夹和文件的权限。我编写了这段代码,它适用于根文件夹中的所有项目,但它不能更改根文件夹本身的权限。我应该在这段代码中改变什么?
property user_name : "suser_root"
property pass_word : "**********"
on open theDroppedItems
repeat with a from 1 to length of theDroppedItems
set theCurrentDroppedItem to item a of theDroppedItems
do shell script "sudo chmod -R 777 " & quoted form of POSIX path of theCurrentDroppedItem user name user_name password pass_word with administrator privileges
end repeat
end open
解决方案
您需要 HOT FOLDER 概念而不是 DROPPLET:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property user_name : "suser_root"
property pass_word : "**********"
on adding folder items to this_folder after receiving theDroppedItems
repeat with a from 1 to length of theDroppedItems
set theCurrentDroppedItem to item a of theDroppedItems
-- make sure dropped item is folder
if (class of item theCurrentDroppedItem of application "Finder") as text is "folder" then
-- unlock dropped folder and its entire contents
tell application "Finder" to set entireContents to (entire contents of folder (theCurrentDroppedItem as text)) as alias list
set end of entireContents to theCurrentDroppedItem
repeat with anAlias in entireContents
set theURL to (current application's class "NSURL"'s fileURLWithPath:(POSIX path of anAlias))
set {theResult, theError} to (theURL's setResourceValue:(false) forKey:(current application's NSURLIsUserImmutableKey) |error|:(reference))
do shell script "chmod -R 777 " & quoted form of POSIX path of anAlias user name user_name password pass_word
end repeat
end if
end repeat
end adding folder items to
推荐阅读
- docker - 为什么当我将 nginx 添加到 docker 时会出现错误:/bin/sh: pip: not found
- jquery - 如何通过模态为所选文本制作超链接
- swift - 如何安全地将 AVKit 与 https 连接?
- javascript - Javascript 二维数组问题
- asp.net - 有没有办法在编译和部署 ASP.Net Web 应用程序后添加模型、数据访问类、Web api 控制器?
- c++ - C ++:使用多种条件验证字符串
- java - 如何从头开始获取线坐标?
- android - 警告:API 'variantOutput.getPackageApplication()' 已过时
- regex - 用于匹配 yyyy-mm-dd 和 mm/dd/yyyy 的正则表达式
- computer-vision - 使用欧几里得距离匹配 SIFT 描述符有什么问题?