In what is entirely out of character for me, I have not tested the following AppleScript as there are other demands on my time today, but it shows you how to:
- Get the folder name from a currently selected folder in the Finder
- Get a list of movie files in the selected folder, or optionally in its folder hierarchy, that match valid movie extensions.
- Test each filename for the string "1080p" or "720p" and set the appropriate tag name.
- Setting the tag name for the selected folder should be straightforward using another conditional block like found in the repeat loop.
- In the setTag handler, the line fileURL's setResourcValue… is one line that has wrapped in the posted content here.
use framework "Cocoa"
use AppleScriptversion "2.4" -- Yosemite or later
use scripting additions
property NSArray : a reference to current application's NSArray
property |NSURL| : a reference to current application's |NSURL|
property NSURLTagNamesKey : a reference to current application'sNSURLTagNamesKey
property valid_movie : {"mp4", "mv4", "mov", "avi"}
property tag1080p : {"1080p"}
property tag720p : {"720p"}
tell application "Finder"
if not (get selection) = {} then
-- set fObject to POSIX path of (selection as text)
set fObject to (selection as text)
log fObject as text
end if
-- recursive drill into specified folder
-- set imageFiles to (every item in entire contents of folder fObject whose kind is movie and valid_movie contains name extension) as alias list
-- just files in first level of folder
set imageFiles to (every item of folder fObject whose kind is movie and valid_movie contains name extension) as alias list
repeat with anItem in imageFiles
if anItem's name contains tag1080p then
set_tag(POSIX path of anItem, tag1080p)
else if anItem's name contains tag720p then
set_tag(POSIX path of anItem, tag720p)
end if
end repeat
end tell
return
on set_tag(afolder, atag)
set tagArray to NSArray'sarrayWithArray:atag
set fileURL to |NSURL|'sfileURLWithPath:afolder
fileURL'ssetResourceValue:tagArrayforKey:NSURLTagNamesKey|error|:missing value
end set_tag