A python libraty for working with macOS tags
Project description
macos-tags
A python library for working with macOS tags.
Installation
pip install macos-tags
Tutorial & Usage
Get all tags:
>>> import macos_tags
>>> macos_tags.tags()
[Tag(name='design', color=None), ..., Tag(name='python', color=<Color.GREEN: 2>]
Get files by tag name:
>>> macos_tags.find("design")
['/Users/home/apple.jpg', '/Users/home/WEB_POSTERS.png']
Count files by tag name:
>>> macos_tags.count("design")
2
List the tags on the file:
>>> path = "/path/to/file"
>>> macos_tags.get_all(path)
[Tag(name='design', color=None), Tag(name='python', color=<Color.GREEN: 2>]
Add a tag to file:
>>> macos_tags.add("design", file=path)
When using
str
objects to define a tag, if a tag does not exist in the system, it will be added without a color label.
Add a new color tag by using Tag
data class and Color
enumeration:
>>> from macos_tags import Tag, Color
>>> tag = Tag(name="python", color=Color.GREEN)
>>> macos_tags.add(tag, file=path)
Add a new color tag using the str
object, where the tag name and color number (from 1 to 7) are separated by the literal \n
:
>>> tag = f"python\n{Color.GREEN}" # == "python\n2"
>>> macos_tags.add(tag, file=path)
If the tag already exists in the system with a different color, the new color will be ignored.
Remove tag from file:
>>> macos_tags.remove(tag, file=path)
Remove all tags from a file at once:
>>> macos_tags.remove_all(path)
Change all tags in the file:
>>> macos_tags.get_all(path)
[Tag(name='design', color=None), Tag(name='python', color=<Color.GREEN: 2>]
>>> new_tags = [Tag("book"), Tag("programming", Color.BLUE)]
>>> macos_tags.set_all(new_tags, file=path)
>>> macos_tags.get_all(path)
[Tag(name="book", color=None), Tag("programming", <Color.BLUE: 4>]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for macos_tags-1.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f8bccb6b85bf3054d13eb17935adc736202e56141a24a6568c98b3f2337d791 |
|
MD5 | c2125b2c1f7c593954567e36dd1e162e |
|
BLAKE2b-256 | f9214ca08aa5b427193e9c3a4da60774ac2f92cd2bd3ed7c924faa7694f7b8ba |