Action

Drafts Wrapped

Posted by agiletortoise, Last update 4 days ago

Ok, this is not Spotify Wrapped - but it’s a quick action that inspects your activity in Drafts for the year 2025 and gives you an summary of drafts created, characters, tags used.

You can change the yr const to use different years.

Steps

  • script

    // change for year
    const yr = 2025
    
    let f = () => {
    	let p = new Prompt()
    	p.title = `Drafts Wrapped ${yr}`
    	p.message = `Generate a summary of your draft library for the ${yr}`
    	p.addButton("Generate")
    	p.isCancellable = true
    	if (!p.show()) { return false }
    
    	let stDate = new QueryDate()
    	stDate.field = "created"
    	stDate.type = "absolute"
    	stDate.date = new Date(yr, 0, 1)
    
    	let endDate = new QueryDate()
    	endDate.field = "created"
    	endDate.type = "absolute"
    	endDate.date = new Date(yr, 11, 31, 23, 59, 59, 999);
    
    	let ws = new Workspace()
    	ws.startDate = stDate
    	ws.endDate = endDate
    
    	let ct = 0
    	let charCt = 0
    	let tags = {}
    	function countTag(tag) {
    		if (tags.hasOwnProperty(tag)) {
    			let n = tags[tag]
    			tags[tag] = n + 1
    		}
    		else {
    			tags[tag] = 1
    		}
    	}
    
    	for (let d of ws.query("all")) {
    		charCt += d.content.length
    		ct += 1
    		for (let t of d.tags) {
    			countTag(t)
    		}
    	}
    
    	const sorted = Object.entries(tags).sort((a, b) => b[1] - a[1])
    	const sortedTags = Object.fromEntries(sorted)
    
    	alert(`In the year ${yr} you...
    	
    Created ${ct} drafts
    Containing ${charCt} characters
    
    With the following tags:
    
    ${Object.keys(sortedTags).map(t => `${t}: ${sortedTags[t]}`).join("\n")}
    	`)
    }
    
    if (!f()) {
    	context.cancel()
    }

Options

  • After Success Nothing
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.