AppleScript递归更改文件的时间戳(用于按名称对FAT32棒进行排序)



由于Mac上没有工具可以按名称对USB记忆棒(FAT32(进行排序,以便在无法自行对文件进行排序的汽车中播放音乐文件,因此我想创建一个小Applescript来执行此操作。 Windows上有像"drivesort"这样的工具可以做到这一点,但由于葡萄酒在Catalina上不起作用,这对我来说是没有选择的。在 mac 上,有许多工具可以从驱动器上的隐藏文件中清除,但我还没有找到任何按名称对 FAT 进行排序的工具......

我的想法是获取文件列表,按名称排序(如果不是(,然后使用 touch 命令更改文件的日期。 据我所知,FAT32 存储的文件未排序,但仅在文件添加到棒上时存储。

这是我的appescript,但它错误地在将设置"a"的行上,它无法转换为预期的类型:

tell application "Finder"
set file_list to every file of entire contents of (choose folder with prompt "Please select directory.")
end tell
repeat with afile in file_list
set a to quoted form of POSIX path of afile
display dialog "aktuelle Datei: " & a as string
do shell script "touch -am " & a
end repeat

我在这里做错了什么? 有没有更好的更简单的方法? 非常感谢!

Finder应该能够对文件进行排序,并调整每个文件的修改日期。 所以像这样的事情(我承认我还没有测试过,但当我在电脑前时会这样做(:

set now to the current date
tell application id "com.apple.Finder" to repeat with f in (sort ¬
the files in my (choose folder)'s entire contents by name)
set [f's modification date, f's creation date, now] to ¬
[now, now, now + 5]
end repeat

通过设置修改日期对所选文件夹进行排序

set now to the current date
set MyFolder to choose folder with prompt "Folder to be sorted"
tell application "Finder"
set SubFolders to every folder of entire contents of MyFolder
-- sort files in the root of the selected folder
tell application id "com.apple.Finder"
repeat with f in ¬
(sort files in MyFolder by name) as alias list
set [f's modification date, now] to [now, now + 60]
end repeat
end tell
-- loop through every subfolders
repeat with aSubFolder in SubFolders
tell application id "com.apple.Finder"
set [aSubFolder's modification date, now] to [now, now + 60]
end tell
tell application id "com.apple.Finder"
repeat with f in ¬
(sort files in aSubFolder by name) as alias list
set [f's modification date, now] to [now, now + 60]
end repeat
end tell
end repeat
end tell

最新更新