Action

Update Upcoming Widget

Posted by agiletortoise, Last update 1 day ago

Example action that uses AI scripting to update the contents of a single draft with a summary of upcoming events and reminders.

For more details on usage of this action, see the related forum tip on creating an “Upcoming” widget.

Example is designed for use as a scheduled automation in Shortcuts, that runs this action in the background periodically, updating the content of that draft - then the draft can be used as the source for a single draft widget that will always display that summary.

Configure the action to change the tag used for the draft or specifics of the prompt used to create the summary.

Requires Drafts Pro, and Drafts v54 or greater running on OS 27

Steps

  • configurationKey

    name
    Tag
    key
    widgetTag
  • configurationKey

    name
    Prompt
    key
    widgetPrompt
  • script

    // get configured values
    const widgetTag = context.configuredValues["widgetTag"]
    const widgetPrompt = context.configuredValues["widgetPrompt"]
    const modelName = context.configuredValues["modelName"]
    
    let f = () => {
    	// find or create draft with specified tag
    	let drafts = Draft.query("", "all", [widgetTag])
    	let d
    	if (drafts.length == 0) {
    		d = new Draft()
    		d.addTag(widgetTag)
    	}
    	else {
    		d = drafts[0]
    	}
    	
    	// prompt model to generate upcoming summary
    	let model = new ModelSession()
    	model.mode = modelName
    	model.toolSets = ["drafts", "events", "reminders"]
    
    	if (!model.isAvailable) {
    		console.log(`Model ${model.mode} not available`)
    		return false
    	}
    	let response = model.respond(widgetPrompt)
    	if (!response) {
    		d.content = `# Upcoming
    
    Unable to update: ${model.lastError}`
    		return false
    	}
    
    	// update draft with response
    	d.content = `# Upcoming
    
    ${response}`
    	d.update()
    	return true
    }
    
    if (!f()) {
    	context.fail()
    }
  • configurationKey

    name
    Model
    key
    modelName

Options

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