From 48d834b3be801529f554551b6b8d2c893819129b Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Thu, 15 Jul 2021 21:06:03 -0700 Subject: [PATCH] Added subject and title, closes #45 --- README.md | 8 ++++++ osxmetadata/__init__.py | 21 +++++++-------- osxmetadata/_version.py | 2 +- osxmetadata/attributes.py | 27 +++++++++++++++++++ osxmetadata/constants.py | 34 ++++++++++++----------- osxmetadata/osxmetadata.py | 55 +------------------------------------- 6 files changed, 65 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index 4bdbe0c..f6e7c4d 100644 --- a/README.md +++ b/README.md @@ -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; @@ -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.| diff --git a/osxmetadata/__init__.py b/osxmetadata/__init__.py index 2e2c196..f08e985 100644 --- a/osxmetadata/__init__.py +++ b/osxmetadata/__init__.py @@ -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, @@ -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, @@ -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 diff --git a/osxmetadata/_version.py b/osxmetadata/_version.py index b0c1238..ce887cf 100644 --- a/osxmetadata/_version.py +++ b/osxmetadata/_version.py @@ -1,3 +1,3 @@ """ osxmetadata version """ -__version__ = "0.99.23" +__version__ = "0.99.24" diff --git a/osxmetadata/attributes.py b/osxmetadata/attributes.py index 085263e..bf72599 100644 --- a/osxmetadata/attributes.py +++ b/osxmetadata/attributes.py @@ -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 diff --git a/osxmetadata/constants.py b/osxmetadata/constants.py index 6548c69..527501e 100644 --- a/osxmetadata/constants.py +++ b/osxmetadata/constants.py @@ -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" @@ -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 @@ -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", ] diff --git a/osxmetadata/osxmetadata.py b/osxmetadata/osxmetadata.py index 7f2e727..a810044 100644 --- a/osxmetadata/osxmetadata.py +++ b/osxmetadata/osxmetadata.py @@ -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, @@ -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?