使用脚本获取系统上最近更改的文件的路径?

使用脚本获取系统上最近更改的文件的路径?

几个月前我问过是否有程序或方法可以访问最近的 Finder 窗口/位置?

在问完这个问题之后我开始使用一个名为新鲜的查看整个系统中最近更改的文件并在弹出菜单中访问它们:

在此处输入图片描述

我喜欢这个,但也希望有某种方式使用脚本来获取系统上最近更改的文件的路径。如何监控文件并获取最近更改的文件列表?

答案1

我不知道如何查看最近修改的文件,但最近打开的文件以十六进制格式存储在 com.apple.recentitems.plist 中。这个 MacScripter 线程包含一个用于获取文件路径的处理程序,但它在 10.8 中停止工作。

on datatoposix(x)
    set f to (open for access POSIX file ("/tmp/datatoposix.dat") with write permission)
    try
         repeat with d in x
              set eof f to 0
              -- Write the data object to the file.
              write d's contents to f
              -- Reset the file mark to byte 21.
              read f from 21 for 0
              set POSIXpath to ""
              repeat
                    -- Read the next 8 bytes as a string and get the characters' IDs.
                    set idList to id of (read f for 8 as string)
                    -- Finish when IDs 2 to 8 aren't the values for "path item".
                    if (idList does not end with {0, 0, 0, 1, 1, 0, 0}) then exit repeat
                    -- Get the byte length of the item's name from the first ID.
                    set len to beginning of idList
                    -- Read that number of bytes as UTF-8 and append the result to the POSIX path.
                    set POSIXpath to POSIXpath & ("/" & (read f for len as «class utf8»))
                    -- Advance the file mark past any padding.
                    read f for (4 - len mod 4) mod 4
              end repeat
              set d's contents to POSIXpath
         end repeat
    on error msg
         display dialog msg
    end try
    close access f
    x
end datatoposix

tell application "System Events"
    tell property list file "~/Library/Preferences/com.apple.recentitems.plist"
        set l to property list item "RecentDocuments"'s property list item ¬
        "CustomListItems"'s property list items's property list item "Bookmark"'s value
    end tell
end tell

datatoposix(l)

相关内容