0

我正在尝试编写一个脚本,该脚本向用户显示一个简单的对话框,其中包含三个选项:“是”、“否”和“取消”。根据用户的输入,脚本会生成两种不同类型的 pdf(特别报告/在线 PDF)或退出流程(如果他们单击“取消”)。到目前为止,这是我想出的。尽管我能够捕获用户的点击,但我无法根据用户的选择运行正确的脚本:

function checkReportType(){
    //draw window
    var askReportWindow = new Window("dialog", "Report Type");    
    askReportWindow.textmissing = askReportWindow.add('statictext{text:"Is this a Special Report?", justify:"center"}');
    var myInputGroup = askReportWindow.add("group");        
    var myButtonGroup = askReportWindow.add("group");
    myButtonGroup.alignment = "right";             
    //add buttons
    var yesButton = myButtonGroup.add("button", undefined, "Yes");   
    var noButton= myButtonGroup.add("button", undefined, "No");
    var cancelButton = myButtonGroup.add("button", undefined, "Cancel"); 
    //setting values to false for "yes" and "no" buttons
    var yesClicked = false;
    var noClicked = false;
    //change button value on click
    yesButton.onClick = function(){
        yesClicked = true;  
        //alert("k");   
    }       
    noButton.onClick = function(){
        noClicked = true; 
        //alert("l");      
    }
    //show window
    askReportWindow.show();
    //check for click
    if(yesClicked===true){
       exportSpecialReport();
    }else if(noClicked===true){
        exportOnlinePDF();
    }else{
        exit();
        askReportWindow.destroy();
    }
}//end checkReportType()
4

3 回答 3

3

function main() {
	var w = new Window ( "dialog", "Please choose to do something…" ),
	u,
	noBtn = w.add('button', u, 'NO' ),
	outBtn = w.add('button', u, 'CANCEL' ),
	yesBtn = w.add('button', u, 'YES' );
	
	noBtn.code = 0;
	outBtn.code = 1;
	yesBtn.code = 2;
	
	w.preferredSize.width = 150;
	w.alignChildren = ["fill", "top"];
	
	noBtn.onClick = outBtn.onClick = yesBtn.onClick = function() {
		w.close(this.code)
	}

	var result = w.show();

	if ( result == 0 ) {
		alert( "user clicked \"NO\"" );
	}
	else if ( result == 1 ) {
		alert( "user clicked \"CANCEL\"" );
	}
	else {
		alert( "user clicked \"YES\"" );
	}
}

于 2017-05-23T10:35:52.783 回答
1

如果您不需要使用 scriptUI,您可以使用 InDesign 内置对话框来执行此操作,如下所示。

/* global app, $*/
var diag = app.dialogs.add({
  name: 'my awesome dialog',
  canCancel: true
});
var col1 = diag.dialogColumns.add();
var radioGrp = col1.radiobuttonGroups.add();
var ctrl1 = radioGrp.radiobuttonControls.add({
  staticLabel: 'selection1',
  checkedState: true
});
var ctrl2 = radioGrp.radiobuttonControls.add({
  staticLabel: 'selection2'
});

if(diag.show() === true) {
  if(ctrl1.checkedState === true) {
    $.writeln('user selected item 1');
  } else if(ctrl2.checkedState === true) {
    $.writeln('user selected item 2');

  }
  diag.destroy();
}
于 2017-05-22T18:37:50.753 回答
0

如果任何 AppleScripters 找到此页面:

if button returned of ¬
    (display dialog "Is this a Special Report?" buttons {"Yes", "No", "Cancel"} default button 2) = "Yes" then
    my exportSpecialReport()
else
    my exportOnlinePDF()
end if
于 2017-05-23T14:03:22.923 回答