Action

Share Ideas to Things

Posted by RosemaryOrchard, Last update over 4 years ago - Unlisted

Steps

  • script

    const alwaysTags = ['Idea'];
    const otherTags = ['The Sweet Setup', 'Podcast'];
    const multiSelect = false;
    
    if (otherTags.length) {
    	let p = Prompt.create();
    	p.title = 'Choose your tags';
    	p.message = draft.title;
    	p.addSelect('tags', 'Tags', otherTags, [], multiSelect);
    	p.addButton('OK');
    
    	let buttonPressed = p.show();
    
    
    	if (buttonPressed) {
    		let tags = alwaysTags.concat(p.fieldValues['tags']);
    		let task = draft.title + ' @tags(' + tags.join(', ') + ')' + "\n\t" + draft.permalink;
    		addTask(tags);
    	}	
    } else {
    	// There are no optional tags, so don't show a prompt
    	let task = draft.content + ' @tags(' + alwaysTags.join(', ') + ')';
    	addTask(alwaysTags);
    }
    
    function addTask(tags) {
    	const baseURL = "things:///add";
    
    	let cb = CallbackURL.create();
    	cb.baseURL = baseURL;
    	cb.addParameter("title", draft.title);
    	cb.addParameter("tags", tags.join(','));
    	cb.addParameter("notes", draft.permalink);
    	
    	let success = cb.open();
    	if (success) {
    		app.displaySuccessMessage('Added task');
    	} else {
    		context.fail('Failed to add task');
    	}
    }

Options

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