applescript 递归更改文件的时间戳(用于按名称对 FAT32 棒进行排序)
applescript change timestamp of files recursevly (for sorting an FAT32-stick by name)
因为 mac 上没有工具可以按名称对 USB 记忆棒 (FAT32) 进行排序,以便在无法自行排序文件的汽车中播放音乐文件,我想创建一个小的 applescript 来做这个。
Windows 上的 "drivesort" 等工具可以执行此操作,但由于 wine 无法在 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
因为 mac 上没有工具可以按名称对 USB 记忆棒 (FAT32) 进行排序,以便在无法自行排序文件的汽车中播放音乐文件,我想创建一个小的 applescript 来做这个。 Windows 上的 "drivesort" 等工具可以执行此操作,但由于 wine 无法在 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