Finderタグの削除(クリア)を行うAppleScriptです。
AppleScript名:Finderファイルタグの設定、取得、クリア |
–Created By Shane Stanley –Modified By Takaaki Naganoya use AppleScript version "2.4" use scripting additions use framework "Foundation" property |NSURL| : a reference to current application’s |NSURL| property NSOrderedSet : a reference to current application’s NSOrderedSet property NSURLTagNamesKey : a reference to current application’s NSURLTagNamesKey set anAlias to (choose file) clearTagsForPath(anAlias) of me –delete tags set aRes to getTagsForPath(anAlias) of me –check — clear all tags on clearTagsForPath(anAlias) set aURL to |NSURL|’s fileURLWithPath:(POSIX path of anAlias) aURL’s setResourceValue:{} forKey:(NSURLTagNamesKey) |error|:(missing value) end clearTagsForPath — get the tags on getTagsForPath(anAlias) set aURL to |NSURL|’s fileURLWithPath:(POSIX path of anAlias) set {theResult, theTags} to aURL’s getResourceValue:(reference) forKey:(NSURLTagNamesKey) |error|:(missing value) if theTags = missing value then return {} — because when there are none, it returns missing value return theTags as list end getTagsForPath — set the tags, replacing any existing on setTagsForPath(tagList, anAlias) set aURL to |NSURL|’s fileURLWithPath:(POSIX path of anAlias) aURL’s setResourceValue:tagList forKey:(NSURLTagNamesKey) |error|:(missing value) end setTagsForPath — add to existing tags on addTagsForPath(tagList, anAlias) set aURL to |NSURL|’s fileURLWithPath:(POSIX path of anAlias) — get existing tags set {theResult, theTags} to aURL’s getResourceValue:(reference) forKey:(NSURLTagNamesKey) |error|:(missing value) if theTags ≠ missing value then — add new tags set tagList to (theTags as list) & tagList set tagList to (NSOrderedSet’s orderedSetWithArray:tagList)’s allObjects() — delete any duplicates end if aURL’s setResourceValue:tagList forKey:(NSURLTagNamesKey) |error|:(missing value) end addTagsForPath |
More from my site
(Visited 292 times, 1 visits today)