Action

Get Draft Info

Posted by Garbonsai, Last update over 3 years ago

Get a titled permalink, wikilink, or the creation or modification date for the current draft and copy it to the clipboard. Edit the action to change the default date format.

Steps

  • defineTemplateTag

    name
    dateformat
    template
    %a, %d %b %Y %T %z
  • script

    // create the prompt
    var p = Prompt.create();
    p.title = 'What draft info?';
    p.message = 'Selection will be copied to the clipboard';
    p.addButton( 'Titled permalink' );
    p.addButton( 'Wikilink' );
    p.addButton( 'Date created' );
    p.addButton( 'Date modified' );
    p.addTextField( 'format', 'Date format', draft.getTemplateTag( 'dateformat' ) );
    
    // show the prompt
    if ( p.show() ) {
    
    	// set the clipboard
    	switch( p.buttonPressed ) {
    		case 'Titled permalink':
    			var info = '[' + draft.displayTitle + '](' + draft.permalink + ')';
    			app.setClipboard( info );
    			break;
    		case 'Wikilink':
    			var info = '[[' + draft.displayTitle + ']]';
    			app.setClipboard( info );
    			break;
    		case 'Date created':
    			var info = strftime( draft.createdAt, p.fieldValues[ 'format' ] );
    			app.setClipboard( info );
    			break;
    		case 'Date modified':
    			var info = strftime( draft.modifiedAt, p.fieldValues[ 'format' ] )
    			app.setClipboard( info );
    			break;
    	}
    	app.displaySuccessMessage( p.buttonPressed + ' copied to the clipboard' );
    }

Options

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