https://github.com/dmkskn/macos-tags
A python library to manipulate tags on macOS
https://github.com/dmkskn/macos-tags
macos macos-tags python
Last synced: about 1 year ago
JSON representation
A python library to manipulate tags on macOS
- Host: GitHub
- URL: https://github.com/dmkskn/macos-tags
- Owner: dmkskn
- License: mit
- Created: 2020-01-21T13:18:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-02T12:47:58.000Z (over 6 years ago)
- Last Synced: 2024-09-23T04:09:42.532Z (over 1 year ago)
- Topics: macos, macos-tags, python
- Language: Python
- Homepage: https://macos-tags.dmkskn.com
- Size: 86.9 KB
- Stars: 26
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Use tags to organize files on Mac from Python

[](http://mypy-lang.org/)
## Installation
```bash
pip install macos-tags
```
Works since Python 3.7.
## Tutorial
Get all tags:
```python
>>> import macos_tags
>>> macos_tags.tags()
[Tag(name='design', color=), ..., Tag(name='python', color=]
```
Get files by tag name:
```python
>>> macos_tags.find("design")
['/Users/home/apple.jpg', '/Users/home/WEB_POSTERS.png']
```
Count files by tag name:
```python
>>> macos_tags.count("design")
2
```
List the tags on the file:
```python
>>> path = "/path/to/file"
>>> macos_tags.get_all(path)
[Tag(name='design', color=), Tag(name='python', color=]
```
Add a tag to file:
```python
>>> 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:
```python
>>> 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`:
```python
>>> 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:
```python
>>> macos_tags.remove(tag, file=path)
```
Remove all tags from a file at once:
```python
>>> macos_tags.remove_all(path)
```
Change all tags in the file:
```python
>>> macos_tags.get_all(path)
[Tag(name='design', color=), Tag(name='python', color=]
>>> 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=), Tag("programming", ]
```
❤️