Finder command - set tag using home-brew tag utility

I’ve installed this GitHub - jdberry/tag: A command line tool to manipulate tags on Mac OS X files, and to query for files with those tags. through home brew which works by in the terminal

command line : WORKS
tag --add done /Users//Desktop/test.txt

but when running the same command in AppleScript I get the ERROR:

sh: tag: command not found

on addTag(filePath as POSIX file, tag)
	do shell script "tag --add " & quoted form of tag & " " & quoted form of POSIX path of filePath
end addTag

add

addTag("/Users/<user>/Desktop/test.txt", "done")

It seems like it’s not using the same terminal environment.

How do I get it to use the terminal environment?

The shell used in Do Shell Script has no idea where in the filesystem the tag command is located, so you need to be explicit about that location. Also, I would not use the name tag for the passed tag string.

I have written this example to find the tag command and accept either a POSIX file or POSIX path from the handler file argument. If you are on an Apple Silicon Mac, and you installed tag from homebrew, then its path will be /opt/homebrew/bin/tag.

use scripting additions

set f to ((path to desktop as text) & "docx-2.txt") as alias
addTag(f, "done")
return

on addTag(afile, tagname)
	do shell script "/usr/local/bin/tag --add " & quoted form of tagname & space & (afile's POSIX path)'s quoted form
end addTag

thanks that makes sense. thanks for the update.