2

我想知道您将如何创建一个动作,您可以在其中突出显示一组文件并从中获取修改日期,然后让它突出显示/选择/标记具有最近日期的文件。

更新:我想在 Applescript 上做,因为我在这方面做得更进一步。这是我到目前为止所拥有的

set dateList to {}
tell application "Finder"
    set inputList to get selection
    repeat with i from 1 to count (inputList)
        set end of dateList to get modification date of item i of inputList
    end repeat
end tell

dateList

--Compare section...

set boolList to {}
set j to 1
repeat with i from 1 to count (dateList)
    if i is (count (dateList)) then
        set j to 0
    end if
    set end of boolList to item i of dateList > item (i + j) of dateList
end repeat

boolList
4

4 回答 4

2

迪克得到了它,但我只是修复了一些东西并做了它,所以它标记了文件而不是弹出窗口。

set dateList to {}
tell application "Finder"
    set inputList to get selection
    repeat with i from 1 to count (inputList)
        set end of dateList to get modification date of item i of inputList
    end repeat
end tell

--Compare section...

set theResult to item 1 of inputList as alias
set theResultDate to item 1 of dateList
set modDate to item 1 of dateList
repeat with i from 1 to count (inputList)
    if dateList's item i > modDate then
        set modDate to dateList's item i
        set theResult to item i of inputList as alias
        set theResultDate to item i of dateList
    end if
end repeat

--Display Result…

--display alert "Most recently modified file in selection:" message "" & theResult & "
--" & theResultDate
tell application "Finder" to set label index of (theResult as alias) to 6

这会将其标记为绿色,如果您想要在索引号 1-8 周围使用不同的颜色,它们显然不按顺序排列。Finder 显然也足够聪明,不会计算其他打开窗口中的选择。

谢谢!

最后,为了使它用作右键单击项目,打开 Automator,创建一个服务,在顶部选择以在文件/文件夹上使用它,将运行 Applescript 拖到那里,粘贴脚本,保存。现在它将在右键单击时可用。一个缺点是文件似乎需要保持选中状态,直到标记某些内容。所以在它工作的时候不要点击。

于 2013-05-06T04:58:06.290 回答
2

查看您现有的 applescript 代码,这应该按上次修改日期对您选择的任何文件进行排序,并将最新结果返回给您的对话框:

set dateList to {}
tell application "Finder"
    set inputList to get selection
    repeat with i from 1 to count (inputList)
        set end of dateList to get modification date of item i of inputList
    end repeat
end tell

--Compare section...

set modDate to item 1 of dateList
repeat with i from 1 to count (inputList)
    if dateList's item i > modDate then
        set modDate to dateList's item i
        set theResult to displayed name of item i of inputList
        set theResultDate to item i of dateList
    end if
end repeat

--Display Result…

display alert "Most recently modified file in selection:" message "" & theResult & "
" & theResultDate
于 2013-05-06T00:24:05.530 回答
1

你让它变得比它需要的更复杂:

tell application "Finder" to reveal item 1 of (sort (get selection) by modification date)
于 2013-05-06T11:32:22.933 回答
0

10.7 和 10.8中存在一个错误,它可以使所有建议的脚本几乎无法使用,具体取决于它们的运行方式。如果您打开一个新的 Finder 窗口并选择一些文件,tell application "Finder" to selection则返回在最前面窗口(或一个空列表)后面的某个窗口中选择的文件。

一种解决方法是将焦点切换到另一个应用程序并返回:

activate app "SystemUIServer"
tell application "Finder"
    activate
    set label index of item 1 of (sort selection by modification date) to 6
end tell

您还可以使用 Run AppleScript 操作创建 Automator 服务,如下所示:

on run {input, parameters}
    tell application "Finder"
        sort (input as alias list) by modification date
        set label index of item 1 of result to 6
    end tell
end run
于 2013-05-06T12:12:51.167 回答