Writing Macro to initiate Publish

Hi there.

I wanted an easy way to initiate the publish synchronisation dialogue for my project so I decided to create a macro.

Actually, my first thought was Commando, but there’s no way to initiate a synchronisation with an existing config, only create a new config or push/diff a selected file.

I’ve found references to the ko.publishing object, but I can find no documentation for it. I am hoping I can pass a config name to fire off the synchronisation dialogue.

Any ideas?

Thanks,
-Travis

Hey @furnox,

The command you’re looking for is


ko.publishing.synchronize('publishing-id')

for example, one from my publishing list is:

ko.publishing.synchronize('eb99997b-cfb1-4803-bacd-b50cd1d2d38c')

I got that by using the Element Inspector and DOM Inspector addons. Commando > Packages > Addons > find the addons and install them

I opened the Tool > Publishing menu and Right click + Shift on one of my Publishing entries.

Another tool that you’ll find handy is the Extension Developer (install through Commando as well). Once it’s installed open Tools > Extension Developer > JS Shell. Here you can play around with the ko.publishing object.

var pubConfig = ko.publishing.getConfigurations()
var prtsrv = Cc["@activestate.com/koPartService;1"].getService(Ci.koIPartService);
var projectUri = ko.uriparse.pathToURI(prtsrv.currentProject.liveDirectory);
// This assumes your project root dir is the same as your local publishing root
// You can do this how ever you like.  You could even ask for 
// the Publishing config name and look for that.
for(i in pubConfig){
    if(pubConfig[i].local_uri === projectUri){
        ko.publishing.synchronize(pubConfig[i].id)
    }
}

I haven’t tested this patch of code. We’re happy to help you further and I’m sure other people have some good ideas too. Hope this helps to get you started though.

  • Carey

Hi Carey.

I’m absolutely thrilled to find a tool like the Extension Dev. JS shell. Makes life a lot easier.

I went with something similar to your code snippet:

var partService = Cc['@activestate.com/koPartService;1'].getService(Ci.koIPartService);
var pubConfig = ko.publishing.getConfigurations();

var prjLongName = partService.currentProject.name;

var reName = /^(.+)\./;
var prjName = reName.exec(prjLongName)[1];

for (var index in pubConfig) {
    if (pubConfig[index].name === prjName) {
        ko.publishing.synchronize(pubConfig[index].id);
        return;
    }
}

As long as I name my publish config after my project, it’ll find it.

Thanks for the help!
-Travis