一个月前捣鼓了一个晚上AppleScript才搞定的简单功能...大多数还是Google到的...事实证明Apple的AppleScript文档非常烂...同时像样的脚本语言+Terminal还是王道...有空时候一定要稍微学学Python...
自动把解压的文件放到Movie目录去
on adding folder items to this_folder after receiving added_items
delay 0.2
set this_folder to alias "Liz's MBP:Users:liz:Downloads:Extract:"
set target_folder to alias "Liz's MBP:Users:liz:Movies:"
set fileList to {}
set fileList to my recursiveSearch(fileList, this_folder)
tell application "Finder"
repeat with aItem in fileList
if name extension of aItem is in {"avi", "wmv", "srt", "idx", "sub", "mkv"} then
if aItem exists then
move aItem to target_folder
end if
end if
end repeat
end tell
end adding folder items to
on recursiveSearch(theList, currentFolder)
tell application "Finder"
set theList to theList & (every file of currentFolder)
set folderList to (every folder of currentFolder)
repeat with newFolder in folderList
set theList to my recursiveSearch(theList, newFolder)
end repeat
return theList
end tell
end recursiveSearch
其实应该没这么复杂...只是如果我只对操作传进来的文件进行处理的话就老是执行不正确...会漏掉几个...总而言之现在就是有个Recursive的Search
使用方法是把它放到root/Library/Scripts/Folder Action Scripts里, 然后绑定在一个文件夹上, 这样有文件改动的时候就会触发
删除空文件夹
--script to find empty folders and delete them
set pathoffolder to alias "Liz's MBP:Users:liz:Downloads:Extract:"
--change folder here
tell application "Finder"
repeat with oneFolder in (get folders of pathoffolder)
if (count items) of oneFolder is 0 or ((count items) of oneFolder is 1 and name of item 1 of oneFolder is ".DS_Store") then delete oneFolder
end repeat
end tell
这个要手动触发...会自动过滤系统文件
No comments:
Post a Comment