Action

Import Folder

Posted by agiletortoise, Last update almost 3 years ago

Import all text files in the folder iCloud Drive/Drafts/Import maintaining the creation date and Finder tags from the files.

Place files in the folder before running. You will be prompted to confirm the number of files to import.

Created drafts will be assigned the tag “import”, do allow easy review of imported content.

Steps

  • defineTemplateTag

    name
    folder-path
    template
    Import
  • defineTemplateTag

    name
    tag
    template
    imported
  • script

    const path = draft.processTemplate("[[folder-path]]");
    const tag = draft.processTemplate("[[tag]]");
    
    let f = () => {
    	let fm = FileManager.createCloud();
    	let files = fm.listContents(path);
    
    	if (files.length == 0) {
    		alert("No files found to import");
    		return false;
    	}
    
    	let p = new Prompt();
    	p.title = "Import Folder";
    	p.message = `${files.length} file(s) found to import.`;
    	p.addButton("Import Now");
    
    	if (!p.show()) {
    		return false;
    	}
    
    	for (let f of files) {
    		let c = fm.readString(f);
    		let cr = fm.getCreationDate(f);
    		let mod = fm.getModificationDate(f);
    		let tags = fm.getTags(f);
    		
    		let d = new Draft();
    		d.content = c;
    		d.createdAt = cr;
    		for (let t of tags) {
    			d.addTag(t);
    		}
    		d.addTag(tag);
    		d.update();
    	}
    
    	alert(`${files.length} draft(s) created.`);
    }
    
    if (!f()) {
    	context.cancel();
    }
    

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.