Re-indexing tags for the purpose of sorting (by tags)

I am using the Plex Media Server for delivering videos to my tv via the Roku Media Player. My files appear in my (Synology) NAS shared drive like this:

File Name tag(s)
Some Random Folder Name 001, Angular, Angular-Testing
A Different Folder 002, Stock-Options
Yet a Different Folder 003, Jiu Jitsu
.
.
.
Folder with a Different Name 380, Python
Folder N 00N, Topic

Each of the folders is filled with some number of video files.

The Hard Part
When I get a new video from my video service, it is indexed at the TOP of the list of folders. That is, the new folder becomes “the new #001”, and the rest of the folders add a number to their place in the folder list.

I would like to adapt this script: https://macscripter.net/viewtopic.php?pid=192126, and use it to do two things:

  1. update the numeric tag to match the position of the folder within the list of folders
  2. keep the other tags the same

I still have to read at least these books to have a clue about AppleScript:

  • Apple Pro Training Series: AppleScript 1-2-3
  • Take Control of Automating Your Mac, 2nd Edition

Thanks for any help at all :slight_smile:

Model: MacBook Pro 2011
AppleScript: Unknown
Browser: Safari 537.36
Operating System: macOS 10.12

Just try locking old folders with READ_ONLY option. Then set the new tag to count of all folders.

remove old script from attached to your hot folder and attach the new you will created.

Your code will be that form:


use framework "Cocoa"
use AppleScript version "2.4" -- Yosemite or later
use scripting additions

property |NSURL| : a reference to current application's |NSURL|
property NSURLTagNamesKey : a reference to current application's NSURLTagNamesKey

on adding folder items to hot_Folder after receiving these_items
	tell application "Finder" to set theFolders to every folder of hot_Folder
	set newFolder to item 1 of theFolders
	set myNumericTAG to count of theFolders
	set myTag to myNumericTAG as string
	if myNumericTAG < 100 then set myTag to "0" & myTag
	if myNumericTAG < 10 then set myTag to "0" & myTag
	set myTag to myTag as list
	set_Tag(newFolder, myTag)
end adding folder items to

on set_Tag(afolder, atag)
	set afolder to POSIX path of (afolder as alias)
	set aURL to current application's |NSURL|'s fileURLWithPath:afolder -- make URL
	aURL's setResourceValue:atag forKey:(current application's NSURLTagNamesKey) |error|:(missing value)
end set_Tag