Action

Make Proxy File and Edit in External Editor

Posted by ernstwi, Last update about 2 years ago

UPDATES

about 2 years ago

Remove TERM_INIT config setting

Part of a workflow for editing drafts in an external editor (Mac only).

See GitHub README for details.

Steps

  • script

    let EDITOR = '';
    
    // ---- CONFIGURATION ----
    // Set EDITOR to the application (note: not shell command) you want to use.
    // Below are some examples.
    
    // TextEdit
    EDITOR = 'TextEdit'
    
    // Visual Studio Code
    // EDITOR = 'Visual Studio Code'
    
    // Neovim Qt
    // EDITOR = 'nvim-qt'
    // -----------------------
    
    function bash(script) {
        let sh = ShellScript.create(`#!/usr/bin/env bash\n${script}`);
        if (!sh.execute()) {
            throw new Error(sh.standardError);
        }
    }
    
    (function() {
        let bookmark = Bookmark.findOrCreate("proxy-files");
        let fm = FileManager.createForBookmark(bookmark);
    
        // TODO: Get file extension from draft
        if (!fm.writeString(`/${draft.uuid}.md`, draft.content)) {
            alert("Error: Couldn't write file");
            return;
        }
    
        let file = `${fm.basePath}/${draft.uuid}.md`;
    
        try {
            bash(`open -a "${EDITOR}" ${file}`);
        } catch (e) {
            alert(e);
            return;
        }
    })();

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.