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

时间:2013-05-05 21:51:36

标签: 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 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 个答案:

答案 0 :(得分: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

答案 1 :(得分:2)

Dick得到了它,但我只修了一些东西并制作了它以便标记文件而不是弹出窗口。

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,粘贴脚本,保存。现在它将在右键单击时可用。一个缺点是,在标记某些内容之前,文件似乎需要保持选定状态。因此,在工作时不要点击。

答案 2 :(得分:1)

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

tell application "Finder" to reveal item 1 of (sort (get selection) by modification date)

答案 3 :(得分:0)

bug in 10.7 and 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

您还可以使用如下运行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