2012-03-12 108 views
1

我想创建一个automator操作来帮助管理DNG/XMP文件。我希望能够将DNG(或多个)拖动到将把DNG和匹配的XMP文件发送到垃圾桶的操作上。除扩展名外,这些文件具有相同的名称,它们位于相同的目录中。例如,IMGP1361.DNG和IMGP1361.xmpAutomator/AppleScript在同一目录中查找具有不同扩展名的相同文件名

这对于shell脚本来说是一个简单的任务,但是有没有Automator的方法来完成它(学习更多关于Automator的知识)?有没有办法获得输入查找程序项目的文件名,将其更改为变量并将其用作另一个操作的输入?

谢谢。

+0

可以很容易地编写一个AppleScript(它可以但不需要,被嵌入的Automator工作流),但我真的不明白这一点:为什么不只是按文件名对Finder视图进行排序,选择所有你想摆脱的文件,然后点击cmd + baskspace? – fanaugen 2012-03-12 08:42:15

+0

好问题 - 我希望能够滚动浏览通过EyeFi卡上传的完整图像的目录,只需拖出那些我不想保存的图像,而不必担心找到要删除的匹配XMP文件(以及不必滚动浏览XMP文件)。 – 2012-03-13 03:58:08

回答

1

好的,明白了。您可以使用下面给出的的Automator工作流内像这样的AppleScript:

Automator workflow

选择文件中查找,如果它的扩展名是ext_list,它会被移动到回收站,等等将在同一文件夹中具有相同名称的所有其他文件的扩展名是also_these_extensions中的那些文件。

它可能是有用的,例如,也用于清洗辅助LaTeX文件的文件夹:只需将"tex"分成ext_list和所有其他分机(如"aux", "dvi", "log")分成also_these_extensions

所选文件不需要位于同一文件夹内;您也可以在Spotlight搜索结果窗口中选择多个项目。

on run {input, parameters} 
    -- for every item having one of these extensions: 
    set ext_list to {"dng"} 
    -- also process items with same name but these extensions: 
    set other_ext_list to {"xmp"} 

    tell application "Finder" 
     set the_delete_list to {} 
     set delete_list to a reference to the_delete_list 
     -- populate list of items to delete 
     repeat with the_item in input 
      set the_item to (the_item as alias) 
      if name extension of the_item is in ext_list then 
       copy the_item to the end of delete_list 
       set parent_folder to (container of the_item) as alias as text 
       set item_name to text 1 thru ((length of (the_item's name as text)) - (length of (the_item's name extension as text))) of (the_item's name as text) 
       repeat with ext in other_ext_list 
        try 
         copy ((parent_folder & item_name & ext) as alias) to the end of delete_list 
        end try 
       end repeat 
      end if 
     end repeat 
     -- delete the items, show info dialog 
     move the_delete_list to the trash 
     display dialog "Moved " & (length of the_delete_list) & " files to the Trash." buttons {"OK"} 
    end tell 
end run 
+0

我试图用这个来做类似的事情,除了删除所有nef/cr2等文件的同时保留dng文件。我看了脚本,是我需要更改“将the_item复制到delete_list结尾”的唯一行吗? – 2013-09-14 15:00:55

2

Automator的此脚本将删除所有共享相同前缀并且其扩展名在grep命令中列出的文件。您也可以添加其他扩展程序。 (XMP | DNG | PDF | XLS)

on run {input, parameters} 
try 
    repeat with anItem in input 
     tell (info for anItem) to set {theName, theExt} to {name, name extension} 
     set shortName to text 1 thru ((get offset of "." & theExt in theName) - 1) of theName 
     tell application "Finder" 
      set parentFolder to parent of anItem as alias 
      set matchList to every paragraph of (do shell script "ls " & POSIX path of parentFolder & " | grep -E '" & shortName & ".(xmp|DNG)'") 
      delete (every file of parentFolder whose name is in matchList) 
     end tell 
    end repeat 
end try 
end run 
+0

其名称中包含短名称是一个危险的过滤器,并且会导致太多文件被删除。所以我不会建议使用上面的代码 – 2012-03-12 17:26:30

+0

你是否更喜欢这个dj? – adayzdone 2012-03-12 20:38:31

+0

我无法做得更好:D(投票) – 2012-03-12 22:37:58

相关问题