Configuration/Setup sending Drafts docs to iA Writer

The action is installed from the dictionary, and I didn’t configured it.

Using this Action: Send to iA Writer | Drafts Directory

And the log says:

Maybe it’s a bug of the iPad version of iA Writer.
I tested callback-urls on iPhone and iPad, and iPad version won’t work either.

Paging @davenicholls. Any ideas? Something in your script is not getting resolved.

Thanks for letting me know Greg,

@moz,

I’ve just tested it on my iPad and it’s working fine. I wondered whether I’d made changes to my version that I had’t pushed to the Action Directory so I downloaded that online version and it also worked.

I also wondered if it was a credential issue with the IA Writer token, but if that’s wrong you get a proper error message.

Have you changed the basePath variable to the IA Writer folder where you want the drafts to be sent?

If that path doesn’t exist then IA writer will return a clear error that the folder isn’t there, but I am wondering whether you accidentally changed the variable name when you edited it. I am talking about the line that reads:

const basePath = "/test/drafts/";

in the original script.

Dave

I just tried to change several settings:

  1. Resetting credential
  2. Try other folder in iA Writer, such as /Locations/Drafts
  3. Using Shortcuts to encode a url and open with a x-callback-url

With folder created in iA Writer, iPhone can work it through, but iPad can’t. Don’t know what’s wrong. I think maybe something wrong with my iPad.

Ok, I think I’ve solved it.

Have you got URL Commands enabled in IA Writer on the iPad?

I’m pretty sure they changed it a while go so it defaults to ‘No’ on installation and has to be manually switched on.

I tried turning it off on my iPad and I got the same error as you.

Dave

1 Like

I don’t know what to say, you’re right Dave. I’m sure I have copied the iA Writer URL token for several times and didn’t notice the button isn’t on. Maybe I need some fresh air. Thank you very much.

You’re very welcome

Cheers

DAve, I am trying to install the send multiple Drafts to iAwriter, but my iAwriter 5.6 settings do not offer a token, so how do I get this token that I get prompted to provide by your action?

Thanks

Manuel

Hi,

In IA Writer you need to go to Settings (for iOS) or Preferences (for Mac). Look for an item about ‘URL commands’. URL commands must be enabled and you will find the token there.

Dave

Hi Dave,

I just cannot make this work! I got the token (but not asking… so I reinstalled the action). when I am presented with the action screen, I input this path to the folder that I want in iAwriter
/Users/manuelescolano/Library/Mobile Documents/27N4MQEA55~pro~writer/Documents/Drafts
Then I tried noth ways:
preselect two drafts on the sidebar (CMD-click) and run the action
use the checkboxes presented in the action screen below Path.

None of this gave me any results

Thanks!

By the way I am talking about Drafts for MAc (I have not tried this in ipad)

HI,

Sorry, I’ve only just seen this.

The path you need to use isn’t the full file path, it is the path within IA Writer’s iCloud folder structure

Based on your example path try using:

const basePath = "/Documents/Drafts/";

Dave

Thanks! I am determined to make this work. I fixed the token and,I think, path issues. I Put my token in the script (I am not getting prompted for it), Path per screenshot here: so just /Drafts/

image

I select 2 -3 test drafts, and after 3 mins (takes a long long time) I get a chime and no drafts in Iawriter.

const baseURL = “ia-writer://x-callback-url/write/”;

var credential = Credential.create(“IA-Writer”, “IA-Writer Token”);

credential.addTextField(“token”, “9nPZZEkHq3RAHERpxiDE”);

var result = credential.authorize();

if (!result) {

alert(“Failed to obtain credentials. Please check and retry”);
context.cancel(“Failed to obtain credentials”);

}
else {

// Find all drafts in the inbox - could be changed to another folder, or to include tags
var inboxDrafts = Draft.query(‘’,‘inbox’,);

var myDrafts = ;

// Put all the title lines in an array for the prompt
for (d in inboxDrafts) {
myDrafts.push(inboxDrafts[d].title);
}

var p = Prompt.create();
p.title = “Choose Drafts”
p.addTextField(“path”, “Save Path”, ‘/Documents/Drafts/’, {})
p.addSelect(“theDrafts”,“Drafts”,myDrafts,,true);

p.addButton(“Ok”);
p.show();

if (p.buttonPressed == “Ok”) {

  var chosenDrafts = p.fieldValues["theDrafts"];
  if (chosenDrafts.length == 0) {
     alert("No Drafts were chosen");
  }
  else {

		basePath = p.fieldValues["path"]
		if (basePath.slice(-1) != "/") {
			basePath += "/Documents/Drafts/"
		}
		for (var d=0;d < chosenDrafts.length; d++) {

        var a = myDrafts.indexOf(chosenDrafts[d]);
        // create and configure callback object
        var cb = CallbackURL.create();
        cb.baseURL = baseURL;
        
        cb.addParameter("auth-token", credential.getValue("token"));
        cb.addParameter("path", basePath+inboxDrafts[a].processTemplate("[[safe_title]]"+".txt"));
        cb.addParameter("text", inboxDrafts[a].content);

        var success = cb.open();

        if (success) {
           console.log("File created: "+ cb.callbackResponse.path);
        }
        else {
           if (cb.status == "cancel") {
              context.cancel();
           }
           else {
              context.fail(cb.callbackResponse.errorMessage);
           }
        }
     }
  }

}
}

The real script I have has has a path just /Drafts/ and not /Documents/Drafts (I had corrected that)

Ok, I think we need to reset things. Could you please do the following:

  1. Delete your current ‘Send multiple to iA writer’ action
  2. Forget the IA=Writer credentials in the Drafts preferences
  3. Download a new copy of the ‘Send Multiple to iA writer’ action
  4. Run the action, leave the ‘path’ as it is (i.e. just ‘/’) and choose a couple of drafts

If it works, then try it again but type the path you want to use into the ‘path’ section the prompt.

Edit: I forgot to say here that leaving the path as ‘/’ means the drafts should appear in the top level folder in iA Writer, the one you get when you just click ‘iCloud’.

If it doesn’t work, go to the Actions menu, chose ‘Action Log’, copy whatever’s in the messages box for the failed action an post the details here.

Thanks

Dave