如何使用Applescript在所有子文件夹中创建相同的新文件?
我希望在每个不存在.DS_存储文件的文件夹和子文件夹中创建一个.DS_存储文件(Mac),然后锁定每个新写入和已存在的.DS_存储文件,然后将每个文件夹的修改日期设置为其中最新的项目 我已经编写了以下代码,这当然不起作用。如果能帮我把这件事做好,我将不胜感激如何使用Applescript在所有子文件夹中创建相同的新文件?,applescript,Applescript,我希望在每个不存在.DS_存储文件的文件夹和子文件夹中创建一个.DS_存储文件(Mac),然后锁定每个新写入和已存在的.DS_存储文件,然后将每个文件夹的修改日期设置为其中最新的项目 我已经编写了以下代码,这当然不起作用。如果能帮我把这件事做好,我将不胜感激 set MyFolder to "Macintosh Backup:Design Photos" tell application "Finder" set SubFolders to ev
set MyFolder to "Macintosh Backup:Design Photos"
tell application "Finder"
set SubFolders to every folder of entire contents of MyFolder
repeat with xFolder in SubFolders
set myFile to path of xFolder & ":.DS_Store"
if not (exists myFile) then
make new file at xFolder with properties {name:".DS_Store"}
end if
set locked of myFile to true
end repeat
end tell
基本上,Finder不知道不可见的文件,除非Finder pref文件中的
AppleShowAllFiles
设置为true。问题是,如果文件在那里,它知道的足够多,会抛出错误。那么,我应该试着绕过那个错误吗?如果是这样的话,这段代码需要什么才能使其全部工作?这里的更高级别目标是什么?DS_存储文件是一种古老且基本上没有文档记录的功能(它们最初用于存储有关文件夹设置的查找器数据)。每次文件夹第一次打开时,Finder都会创建它们,并在更改文件夹GUI或内容时修改它们。我不知道如果你试图锁上它们,会有什么东西断裂,但断裂似乎很可能。也许有不同的方式来实现你的目标?附言:在回复评论时,你应该包括一个“at”标签:例如,@macuseronline。这将通知其他人您已响应。只是让您知道@和name之间没有空格,例如@macuseronline@user3439894所采取的观点…所做的更改
set myFolder to "Macintosh Backup:Design Photos"
tell application "Finder"
set subFolders to every folder of entire contents of folder myFolder
repeat with xFolder in subFolders
try -- avoids error if no files exist
set modificationDate to modification date of last item of ¬
(sort (get files of xFolder) by modification date)
end try
set myFile to ((xFolder as text) & ".DS_Store")
if not (exists alias myFile) then
set myFile to make new file at xFolder ¬
with properties {name:".DS_Store"}
set locked of myFile to true
else
set locked of alias myFile to true
end if
try -- avoids error if no files exist
set modification date of xFolder to modificationDate
end try
end repeat
end tell