Giter Site home page Giter Site logo

macos-tags's Introduction

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>]

❤️

macos-tags's People

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.