Action

Working Copy round trip : fetch

Posted by @derekvan, Last update about 5 years ago

This script will allow you to choose any file from a working copy repo and import it to Drafts. It also copies the universal URL of the file, so that when you use the associated “put” Drafts action, the file commits without needing any input from the user about where to save it.

Steps

  • script

    // Working Copy fetch
    // Grab file from working copy, prepend with universal URL link to facilitate git commit 
    
    const credential = Credential.create("Working Copy Key", "The URL key for Working Copy");
    
    credential.addTextField("key", "URL key");
    
    credential.authorize();
    
    const key = credential.getValue("key");
    
    const baseURL = "working-copy://x-callback-url/read/?";
    
    var cb = CallbackURL.create();
    cb.baseURL = baseURL;
    cb.addParameter("type", "url");
    
    let success = cb.open();
    
    var wcf = CallbackURL.create();
    wcf.baseURL = baseURL;
    wcf.addParameter("url",cb.callbackResponse.url);
    wcf.addParameter("key",key);
    
    let good = wcf.open();
    
    let d = Draft.create();
    
    d.content = cb.callbackResponse.url + "\n" + wcf.callbackResponse.text;
    
    d.update();

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.