Skip to main content

Use tags to organize files on Mac from Python

Release Checked with mypy

Installation

pip install macos-tags

Works since Python 3.7.

Tutorial

Get all tags:

>>> import macos_tags


>>> macos_tags.tags()
[Tag(name='design', color=<Color.NONE: 0>), ..., 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=<Color.NONE: 0>), 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=<Color.NONE: 0>), 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=<Color.NONE: 0>), Tag("programming", <Color.BLUE: 4>]

❤️

Release files for macos-tags 1.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for macos-tags 1.5.1
File Size Uploaded
macos-tags-1.5.1.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for macos-tags 1.5.1
File Interpreter ABI Platform
macos_tags-1.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.7 kB

Release files / macos-tags-1.5.1.tar.gz

Download URL macos-tags-1.5.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f144c5bc05d01573966d8aca2483cb345b20b76a5b32e9967786e086a38712e7
BLAKE2b-256 checksum
How to use checksums
d46ee0b2ea37ef831a5c6b5aebbd14701d96d9dc061f04a867b05335a4bc099d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.3 CPython/3.7.6 Darwin/19.3.0

Release files / macos_tags-1.5.1-py3-none-any.whl

Download URL macos_tags-1.5.1-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56419233af32242b703dd35bcf38c9f198abd969faddbe986eb8aaa6d95349cf
BLAKE2b-256 checksum
How to use checksums
0c068ae35dcdd7518cbdf84f06c48670b563a2835abe2089e77cedd5cff0110c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.3 CPython/3.7.6 Darwin/19.3.0

Release history Release notifications | RSS feed

This release

1.5.1 This release

2 release files

1.5.0

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page