Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Removing unused tags from Evernote
// main.m
// Tag Cleaner
// Created by Dave DeLong on 11/17/12.
// Copyright (c) 2012 Dave DeLong. All rights reserved.
// requires
#import <Foundation/Foundation.h>
#import "EDAMErrors.h"
#import "EDAMLimits.h"
#import "EDAMNoteStore.h"
#import "EDAMTypes.h"
#import "EDAMUserStore.h"
#import "TBinaryProtocol.h"
#import "TProtocol.h"
#import "TProtocolException.h"
#import "TProtocolFactory.h"
#import "TProtocolUtil.h"
#import "TApplicationException.h"
#import "TException.h"
#import "TProcessor.h"
#import "TProcessorFactory.h"
#import "THTTPClient.h"
#import "TMemoryBuffer.h"
#import "TTransport.h"
#import "TTransportException.h"
#import "TSharedProcessorFactory.h"
// You can acquire a Developer Token from
NSString * const ENDeveloperToken = @"...";
int main(int argc, const char * argv[]) {
@autoreleasepool {
THTTPClient *httpClient = [[THTTPClient alloc] initWithURL:[NSURL URLWithString:@""]];
TBinaryProtocol *userStoreProtocol = [[TBinaryProtocol alloc] initWithTransport:httpClient];
EDAMUserStoreClient *userStoreClient = [[EDAMUserStoreClient alloc] initWithProtocol:userStoreProtocol];
NSString *noteStoreString = [userStoreClient getNoteStoreUrl:ENDeveloperToken];
NSURL *noteStoreURL = [NSURL URLWithString:noteStoreString];
THTTPClient *noteStoreTransport = [[THTTPClient alloc] initWithURL:noteStoreURL];
TBinaryProtocol *noteStoreProtocol = [[TBinaryProtocol alloc] initWithTransport:noteStoreTransport];
EDAMNoteStoreClient *noteStoreClient = [[EDAMNoteStoreClient alloc] initWithProtocol:noteStoreProtocol];
NSArray *tags = [noteStoreClient listTags:ENDeveloperToken];
NSInteger counter = 0;
for (id tag in tags) {
NSArray *tagGuids = @[[tag guid]];
EDAMNoteFilter *filter = [[EDAMNoteFilter alloc] initWithOrder:0 ascending:YES words:nil notebookGuid:nil tagGuids:tagGuids timeZone:nil inactive:NO];
EDAMNoteCollectionCounts *counts = [noteStoreClient findNoteCounts:ENDeveloperToken :filter :NO];
NSDictionary *tagCounts = [counts tagCounts];
id count = [tagCounts objectForKey:[tag guid]];
if (count == nil || [count integerValue] == 0) {
[noteStoreClient expungeTag:ENDeveloperToken :[tag guid]];
NSLog(@"expunged %ld unused tags", counter);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment