openURL Script?

I can’t figure out how openURL works. I will be replacing the URLs with the KeyboardMaestri actions URLs but for the sake of figuring out how this works, I included basic links. Does not seem to work. Please advise,

editor.activate();

var one = ‘www.google.ca’;
var two = ‘www.duckduckgo.con’;
var p = Prompt.create();

p.title = “Export Report to Pages”;
p.message = “Which Clinic?”;

p.addButton(“one”);
p.addButton(“two”);

var didSelect = p.show();

if (p.buttonPressed == “one”) {
app.openURL(one);
}
else {Safari.openURL(‘www.google.ca’);
}

I am wondering if it might be just the protocol missing on that strings.

Did you try ‘https://www.google.ca

That worked on my iPhone.

1 Like

As @Andreas_Haberle notes, to make it a URL you need the protocol. It isn’t a URL without it.

But you have also added

else {Safari.openURL('www.google.ca');
}

but Safari is not a Drafts class and not one you have defined.

Try changing that to be app; maybe more like this.

else app.openURL('https://www.google.ca');

Also don’t forget to use triple back ticks for your code blocks to stop the forum changing some of the characters; you look to have used a comment block and it has and your quotation marks.

I figured it out. Thank you.

editor.activate();

var gbppc = 'kmtrigger://macro=MVA%20Report%20-%20GBPPC';
var allied = 'kmtrigger://macro=MVA%20Report%20-%20Allied%20Med';

var p = Prompt.create();

p.title = "Export Report to Pages";
p.message = "Which Clinic?";

p.addButton('GBPPC');
p.addButton('Allied Med');

p.show();

if (p.buttonPressed == 'GBPPC')	{app.openURL(gbppc);
}
	else {app.openURL(allied);
}
2 Likes