Skip to content

Commit

Permalink
Added subject and title, closes #45
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Jul 16, 2021
1 parent 5ce8876 commit 48d834b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 82 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,16 @@ stationarypad stationarypad, com.apple.FinderInfo; Marks the file as
stationary (a template that can be re-used). Setting this to
True is the same as checking the 'Stationary Pad' box in
Finder Info.
subject kMDItemSubject, com.apple.metadata:kMDItemSubject; Subject
of the this item. A string.
tags _kMDItemUserTags, com.apple.metadata:_kMDItemUserTags;
Finder tags; searchable in Spotlight using "tag:tag_name".
If you want tags/keywords visible in the Finder, use this
instead of kMDItemKeywords. A list of Tag objects.
title kMDItemTitle, com.apple.metadata:kMDItemTitle; The title of
the file. For example, this could be the title of a
document, the name of a song, or the subject of an email
message. A string.
version kMDItemVersion, com.apple.metadata:kMDItemVersion; The
version number of this file. A string.
wherefroms kMDItemWhereFroms, com.apple.metadata:kMDItemWhereFroms;
Expand Down Expand Up @@ -257,7 +263,9 @@ Information about commonly used MacOS metadata attributes is available from [App
|kMDItemStarRating|rating|com.apple.metadata:kMDItemStarRating|User rating of this item. For example, the stars rating of an iTunes track. An integer.|
|kMDItemFSIsStationery|stationary|com.apple.metadata:kMDItemFSIsStationery|Boolean indicating if this file is stationery. Note: this is not what the Finder uses for Stationary Pad flag. See also 'stationarypad'.|
|stationarypad|stationarypad|com.apple.FinderInfo|Marks the file as stationary (a template that can be re-used). Setting this to True is the same as checking the 'Stationary Pad' box in Finder Info.|
|kMDItemSubject|subject|com.apple.metadata:kMDItemSubject|Subject of the this item. A string.|
|_kMDItemUserTags|tags|com.apple.metadata:_kMDItemUserTags|Finder tags; searchable in Spotlight using "tag:tag_name". If you want tags/keywords visible in the Finder, use this instead of kMDItemKeywords. A list of Tag objects.|
|kMDItemTitle|title|com.apple.metadata:kMDItemTitle|The title of the file. For example, this could be the title of a document, the name of a song, or the subject of an email message. A string.|
|kMDItemVersion|version|com.apple.metadata:kMDItemVersion|The version number of this file. A string.|
|kMDItemWhereFroms|wherefroms|com.apple.metadata:kMDItemWhereFroms|Describes where the file was obtained from (e.g. URL downloaded from). A list of strings.|

Expand Down
21 changes: 9 additions & 12 deletions osxmetadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
from ._version import __version__
from .attributes import ATTRIBUTES
from .constants import (
_COLORIDS,
_COLORNAMES,
_FINDER_COMMENT_NAMES,
_MAX_FINDERCOMMENT,
_MAX_WHEREFROM,
_VALID_COLORIDS,
FINDER_COLOR_BLUE,
FINDER_COLOR_GRAY,
FINDER_COLOR_GREEN,
Expand All @@ -19,6 +13,12 @@
FINDER_COLOR_RED,
FINDER_COLOR_YELLOW,
FinderInfo,
_COLORIDS,
_COLORNAMES,
_FINDER_COMMENT_NAMES,
_MAX_FINDERCOMMENT,
_MAX_WHEREFROM,
_VALID_COLORIDS,
_kMDItemUserTags,
kMDItemAuthors,
kMDItemComment,
Expand All @@ -32,15 +32,12 @@
kMDItemParticipants,
kMDItemProjects,
kMDItemStarRating,
kMDItemSubject,
kMDItemTitle,
kMDItemUserTags,
kMDItemVersion,
kMDItemWhereFroms,
)
from .debug import _debug, _set_debug
from .findertags import (
Tag,
# get_finderinfo_color,
get_tag_color_name,
# set_finderinfo_color,
)
from .findertags import Tag, get_tag_color_name
from .osxmetadata import OSXMetaData
2 changes: 1 addition & 1 deletion osxmetadata/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
""" osxmetadata version """

__version__ = "0.99.23"
__version__ = "0.99.24"
27 changes: 27 additions & 0 deletions osxmetadata/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,33 @@
+ "Setting this to True is the same as checking the 'Stationary Pad' box in Finder Info.",
api_help=None,
),
"title": Attribute(
name="title",
short_constant="kMDItemTitle",
constant=kMDItemTitle,
type_=str,
list=False,
as_list=False,
class_=str,
append=True,
update=False,
help="The title of the file. For example, this could be the title of a document, the name of a song, "
+"or the subject of an email message. A string.",
api_help=None,
),
"subject": Attribute(
name="subject",
short_constant="kMDItemSubject",
constant=kMDItemSubject,
type_=str,
list=False,
as_list=False,
class_=str,
append=True,
update=False,
help="Subject of the this item. A string.",
api_help=None,
)
}

# used for formatting output of --list
Expand Down
34 changes: 19 additions & 15 deletions osxmetadata/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# tag color is 3 bits
_kCOLOR_OFFSET = 76

#offset of stationary pad bit in com.apple.FinderInfo xattr
# offset of stationary pad bit in com.apple.FinderInfo xattr
_kSTATIONARYPAD_OFFSET = 68

# _TAGS = "com.apple.metadata:_kMDItemUserTags"
Expand All @@ -65,25 +65,27 @@
# _DOWNLOAD_DATE = "com.apple.metadata:kMDItemDownloadedDate"


FinderInfo = "com.apple.FinderInfo"
_kMDItemUserTags = "com.apple.metadata:_kMDItemUserTags"
kMDItemAuthors = "com.apple.metadata:kMDItemAuthors"
kMDItemComment = "com.apple.metadata:kMDItemComment"
kMDItemCopyright = "com.apple.metadata:kMDItemCopyright"
kMDItemCreator = "com.apple.metadata:kMDItemCreator"
kMDItemDescription = "com.apple.metadata:kMDItemDescription"
kMDItemDownloadedDate = "com.apple.metadata:kMDItemDownloadedDate"
kMDItemDueDate = "com.apple.metadata:kMDItemDueDate"
kMDItemFSIsStationery = "com.apple.metadata:kMDItemFSIsStationery"
kMDItemFinderComment = "com.apple.metadata:kMDItemFinderComment"
kMDItemHeadline = "com.apple.metadata:kMDItemHeadline"
kMDItemKeywords = "com.apple.metadata:kMDItemKeywords"
_kMDItemUserTags = "com.apple.metadata:_kMDItemUserTags"
kMDItemUserTags = "com.apple.metadata:_kMDItemUserTags"
kMDItemWhereFroms = "com.apple.metadata:kMDItemWhereFroms"
kMDItemDueDate = "com.apple.metadata:kMDItemDueDate"
FinderInfo = "com.apple.FinderInfo"
kMDItemStarRating = "com.apple.metadata:kMDItemStarRating"
kMDItemParticipants = "com.apple.metadata:kMDItemParticipants"
kMDItemProjects = "com.apple.metadata:kMDItemProjects"
kMDItemStarRating = "com.apple.metadata:kMDItemStarRating"
kMDItemSubject = "com.apple.metadata:kMDItemSubject"
kMDItemTitle = "com.apple.metadata:kMDItemTitle"
kMDItemUserTags = "com.apple.metadata:_kMDItemUserTags"
kMDItemVersion = "com.apple.metadata:kMDItemVersion"
kMDItemFSIsStationery = "com.apple.metadata:kMDItemFSIsStationery"
kMDItemWhereFroms = "com.apple.metadata:kMDItemWhereFroms"


# Special handling for Finder comments
Expand All @@ -98,23 +100,25 @@
_BACKUP_FILENAME = ".osxmetadata.json"

__all__ = [
"FinderInfo",
"_kMDItemUserTags",
"kMDItemAuthors",
"kMDItemComment",
"kMDItemCopyright",
"kMDItemCreator",
"kMDItemDescription",
"kMDItemDownloadedDate",
"kMDItemDueDate",
"kMDItemFSIsStationery",
"kMDItemFinderComment",
"kMDItemHeadline",
"kMDItemKeywords",
"kMDItemUserTags",
"_kMDItemUserTags",
"kMDItemWhereFroms",
"kMDItemDueDate",
"FinderInfo",
"kMDItemStarRating",
"kMDItemParticipants",
"kMDItemProjects",
"kMDItemStarRating",
"kMDItemSubject",
"kMDItemTitle",
"kMDItemUserTags",
"kMDItemVersion",
"kMDItemFSIsStationery",
"kMDItemWhereFroms",
]
55 changes: 1 addition & 54 deletions osxmetadata/osxmetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,10 @@
from .attributes import ATTRIBUTES, Attribute, validate_attribute_value
from .classes import _AttributeList, _AttributeTagsList
from .constants import (
_COLORIDS,
_COLORNAMES,
_FINDER_COMMENT_NAMES,
_MAX_FINDERCOMMENT,
_MAX_WHEREFROM,
_VALID_COLORIDS,
FINDER_COLOR_BLUE,
FINDER_COLOR_GRAY,
FINDER_COLOR_GREEN,
FINDER_COLOR_NONE,
FINDER_COLOR_ORANGE,
FINDER_COLOR_PURPLE,
FINDER_COLOR_RED,
FINDER_COLOR_YELLOW,
FinderInfo,
_kMDItemUserTags,
kMDItemAuthors,
kMDItemComment,
kMDItemCopyright,
kMDItemCreator,
kMDItemDescription,
kMDItemDownloadedDate,
kMDItemFinderComment,
kMDItemHeadline,
kMDItemKeywords,
kMDItemParticipants,
kMDItemProjects,
kMDItemStarRating,
kMDItemUserTags,
kMDItemVersion,
kMDItemWhereFroms,
kMDItemFSIsStationery,
FINDER_COLOR_NONE,
)
from .datetime_utils import (
datetime_naive_to_utc,
Expand All @@ -62,31 +34,6 @@
from .findertags import Tag, get_tag_color_name


__all__ = [
"OSXMetaData",
"__version__",
"ATTRIBUTES",
"kMDItemAuthors",
"kMDItemComment",
"kMDItemCopyright",
"kMDItemCreator",
"kMDItemDescription",
"kMDItemDownloadedDate",
"kMDItemFinderComment",
"kMDItemHeadline",
"kMDItemKeywords",
"kMDItemUserTags",
"_kMDItemUserTags",
"kMDItemWhereFroms",
"kMDItemDueDate",
"kMDItemStarRating",
"kMDItemParticipants",
"kMDItemProjects",
"kMDItemVersion",
"kMDItemFSIsStationery",
]


# TODO: What to do about colors
# TODO: check what happens if OSXMetaData.__init__ called with invalid file--should result in error but saw one case where it didn't
# TODO: cleartags does not always clear colors--this is a new behavior, did Mac OS change something in implementation of colors?
Expand Down

0 comments on commit 48d834b

Please sign in to comment.