Applescript:突出显示组中最近的文件

Applescript:突出显示组中最近的文件,applescript,workflow,organization,Applescript,Workflow,Organization,我想知道您如何创建一个操作,您可以突出显示一组文件并从中获取修改日期,然后让它突出显示/选择/标记文件的最新日期 更新:我想在Applescript上这样做,因为我在这方面做得更深入了。这是我到目前为止所拥有的 set dateList to {} tell application "Finder" set inputList to get selection repeat with i from 1 to count (inputList) set end of

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

更新:我想在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

查看现有的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

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

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,创建一个服务,在顶部选择以在文件/文件夹上使用它,将Run Applescript拖到其中,粘贴脚本,保存。现在,右键单击即可使用。一个缺点是,文件似乎需要保持选中状态,直到有东西被标记。因此,在它工作时不要单击。

您使它变得比需要的更复杂:

tell application "Finder" to reveal item 1 of (sort (get selection) by modification date)
有一种方法可以使所有建议的脚本几乎不可用,这取决于它们的运行方式。如果打开新的Finder窗口并选择一些文件,
告诉应用程序“Finder”进行选择
返回在最前面窗口(或空列表)后面的某个窗口中选择的文件

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

activate app "SystemUIServer"
tell application "Finder"
    activate
    set label index of item 1 of (sort selection by modification date) to 6
end tell
您还可以使用运行AppleScript操作创建自动机服务,如下所示:

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

要在Applescript或Automator中执行此操作吗?它们是两个不同的东西。据我所知,自动机更像是一个GUI应用程序脚本。不过,只要结果能够添加到上下文菜单项中,Sautomator就使用“工作流”,这与直接使用Applescript不同。Automator工作流可以触发Applescripts,尽管工作流不仅仅是Applescript之上的gui。哦,一直认为Automator中的步骤就像简化了的Applescript代码包。不管怎样,我决定用applescript来写,因为我在这方面做得更深入了。编辑输入。你的Applescript看起来不错,并且似乎返回了正确的结果-那么你希望如何按照你所说的返回或突出显示信息?嘿,伙计,这是一份很棒的工作,但是你遗漏了一些东西,导致它再次依赖于选择顺序,请参阅我的答案。谢谢非常感谢。我不确定你到底想让它怎么显示出来,尽管我很高兴你能弄明白。在最新的文件上使用标签很好。:)