// ScriptUI examples // This example shows how to use ScriptUI to create user interfaces to // your script and get values in and out. // To Use: // set currentStep to 0 // Reset Photoshop preferences // Restart photoshop // increment this value and run again to see each example in turn var currentStep = 0; // uncomment the following line to run them all // for ( var currentStep = 0; true; currentStep++ ) switch ( currentStep ) { case 0: // 0 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.show(); break; case 1: // 1 var dlg = new Window('dialog'); dlg.text = 'Howdy'; var okBtn = dlg.add('button'); okBtn.text = 'ok'; var cancelBtn = dlg.add('button'); cancelBtn.text = 'cancel'; dlg.center(); dlg.show(); break; case 2: // 2 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ }'; var dlg = new Window(dlgResource); dlg.center(); if ( 1 == dlg.show() ) { alert('ok'); } else { alert('cancel'); } break; case 3: // 3 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ btnThird : Button { text: "third" }, \ }'; var dlg = new Window(dlgResource); dlg.center(); if ( 1 == dlg.show() ) { alert('ok'); } else { alert('cancel'); } break; case 4: // 4 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ btnThird : Button { text: "third" }, \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.cancelElement = dlg.btnThird; if ( 1 == dlg.show() ) { alert('ok'); } else { alert('cancel'); } break; case 5: // 5 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "tom says ok" }, \ btnCancel : Button { text: "cancel" }, \ btnThird : Button { text: "third" }, \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.cancelElement = dlg.btnThird; if ( 1 == dlg.show() ) { alert('ok'); } else { alert('cancel'); } break; case 6: // 6 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "tom says ok", properties : { name: "ok" } }, \ btnCancel : Button { text: "cancel" }, \ btnThird : Button { text: "third" }, \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.cancelElement = dlg.btnThird; if ( 1 == dlg.show() ) { alert('ok'); } else { alert('cancel'); } break; case 7: // 7 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ btnThird : Button { text: "third" }, \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.btnThird.onClick = function() { alert('stop it'); } if ( 1 == dlg.show() ) { alert('ok'); } else { alert('cancel'); } break; case 8: // 8 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ stThird : StaticText { text: "third" }, \ etEditText : EditText { text: "get something" }, \ rbRadioButton1 : RadioButton { text: "1 radio" }, \ rbRadioButton2 : RadioButton { text: "2 radio" }, \ rbRadioButton3 : RadioButton { text: "3 radio" }, \ cbCheckBox : Checkbox { text: "1 check box" }, \ ddDrpopDown : DropDownList { properties: { \ items: [ "JPEG", "TIFF", "PSD", "GIF" ] } }, \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.show(); break; case 9: // 9 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ stThird : StaticText { text: "third" }, \ etEditText : EditText { text: "get something" }, \ rbRadioButton1 : RadioButton { text: "1 radio" }, \ rbRadioButton2 : RadioButton { text: "2 radio" }, \ rbRadioButton3 : RadioButton { text: "3 radio" }, \ cbCheckBox : Checkbox { text: "1 check box" }, \ ddDropDown : DropDownList { properties: { \ items: [ "JPEG", "TIFF", "PSD", "GIF" ] } }, \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.stThird.text = "fourth"; dlg.etEditText.text = "got milk"; dlg.rbRadioButton2.value = true; dlg.cbCheckBox.value = true; dlg.ddDropDown.items[ 2 ].selected = true; dlg.show(); break; case 10: // 10 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ stThird : StaticText { text: "third" }, \ etEditText : EditText { text: "get something" }, \ rbRadioButton1 : RadioButton { text: "1 radio" }, \ rbRadioButton2 : RadioButton { text: "2 radio" }, \ rbRadioButton3 : RadioButton { text: "3 radio" }, \ cbCheckBox : Checkbox { text: "1 check box" }, \ ddDropDown : DropDownList { properties: { \ items: [ "JPEG", "TIFF", "PSD", "GIF" ] } }, \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.stThird.text = "fourth"; dlg.etEditText.text = "got milk"; dlg.rbRadioButton2.value = true; dlg.cbCheckBox.value = true; dlg.ddDropDown.items[ 2 ].selected = true; if ( 1 == dlg.show() ) { alert( dlg.etEditText.text + '\r' + dlg.rbRadioButton1.value + '\r' + dlg.rbRadioButton2.value + '\r' + dlg.rbRadioButton3.value + '\r' + dlg.cbCheckBox.value + '\r' + dlg.ddDropDown.selection.text ); } break; case 11: // 11 var dlgResource = 'dialog { text: "Hello", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ stThird : StaticText { text: "third" }, \ etEditText : EditText { text: "get something" }, \ rbRadioButton1 : RadioButton { text: "1 radio" }, \ rbRadioButton2 : RadioButton { text: "2 radio" }, \ rbRadioButton3 : RadioButton { text: "3 radio" }, \ cbCheckBox : Checkbox { text: "1 check box" }, \ ddDropDown : DropDownList { properties: { \ items: [ "JPEG", "TIFF", "PSD", "GIF" ] } }, \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.stThird.text = "fourth"; dlg.etEditText.text = "got milk"; dlg.rbRadioButton2.value = true; dlg.cbCheckBox.value = true; dlg.ddDropDown.items[ 2 ].selected = true; dlg.stThird.enabled = false; dlg.rbRadioButton2.onClick = function() { this.parent.stThird.enabled = this.value; } dlg.rbRadioButton1.onClick = function() { this.parent.stThird.enabled = ! this.value; } dlg.cbCheckBox.onClick = function() { this.parent.ddDropDown.visible = this.value; this.parent.etEditText.active = this.value; } if ( 1 == dlg.show() ) { alert( dlg.etEditText.text + '\r' + dlg.rbRadioButton1.value + '\r' + dlg.rbRadioButton2.value + '\r' + dlg.rbRadioButton3.value + '\r' + dlg.cbCheckBox.value + '\r' + dlg.ddDropDown.selection.text ); } break; case 12: // 12 var dlgResource = 'dialog { text: "Hello", orientation: "row", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ stThird : StaticText { text: "third" }, \ etEditText : EditText { text: "get something" }, \ rbRadioButton1 : RadioButton { text: "1 radio" }, \ rbRadioButton2 : RadioButton { text: "2 radio" }, \ rbRadioButton3 : RadioButton { text: "3 radio" }, \ cbCheckBox : Checkbox { text: "1 check box" }, \ ddDropDown : DropDownList { properties: { \ items: [ "JPEG", "TIFF", "PSD", "GIF" ] } }, \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.stThird.text = "fourth"; dlg.etEditText.text = "got milk"; dlg.rbRadioButton2.value = true; dlg.cbCheckBox.value = true; dlg.ddDropDown.items[ 2 ].selected = true; dlg.stThird.enabled = false; dlg.rbRadioButton2.onClick = function() { this.parent.stThird.enabled = this.value; } dlg.rbRadioButton1.onClick = function() { this.parent.stThird.enabled = ! this.value; } dlg.cbCheckBox.onClick = function() { this.parent.ddDropDown.visible = this.value; this.parent.etEditText.active = this.value; } if ( 1 == dlg.show() ) { alert( dlg.etEditText.text + '\r' + dlg.rbRadioButton1.value + '\r' + dlg.rbRadioButton2.value + '\r' + dlg.rbRadioButton3.value + '\r' + dlg.cbCheckBox.value + '\r' + dlg.ddDropDown.selection.text ); } break; case 13: // 13 var dlgResource = 'dialog { text: "Hello", orientation: "row", \ grpStuff : Group { orientation: "column", alignChildren: "left", \ stThird : StaticText { text: "third" }, \ etEditText : EditText { text: "get something" }, \ rbRadioButton1 : RadioButton { text: "1 radio" }, \ rbRadioButton2 : RadioButton { text: "2 radio" }, \ rbRadioButton3 : RadioButton { text: "3 radio" }, \ cbCheckBox : Checkbox { text: "1 check box" }, \ ddDropDown : DropDownList { properties: { \ items: [ "JPEG", "TIFF", "PSD", "GIF" ] } }, \ }, \ grpButtons : Group { orientation: "column", alignment: "top", \ btnOK : Button { text: "ok" }, \ btnCancel : Button { text: "cancel" }, \ } \ }'; var dlg = new Window(dlgResource); dlg.center(); dlg.grpStuff.stThird.text = "fourth"; dlg.grpStuff.etEditText.text = "got milk"; dlg.grpStuff.etEditText.minimumSize.width = 100; dlg.grpStuff.rbRadioButton2.value = true; dlg.grpStuff.cbCheckBox.value = true; dlg.grpStuff.ddDropDown.items[ 2 ].selected = true; dlg.grpStuff.stThird.enabled = false; dlg.grpStuff.rbRadioButton2.onClick = function() { this.parent.stThird.enabled = this.value; } dlg.grpStuff.rbRadioButton1.onClick = function() { this.parent.stThird.enabled = ! this.value; } dlg.grpStuff.cbCheckBox.onClick = function() { this.parent.ddDropDown.visible = this.value; this.parent.etEditText.active = this.value; } if ( 1 == dlg.show() ) { alert( dlg.grpStuff.etEditText.text + '\r' + dlg.grpStuff.rbRadioButton1.value + '\r' + dlg.grpStuff.rbRadioButton2.value + '\r' + dlg.grpStuff.rbRadioButton3.value + '\r' + dlg.grpStuff.cbCheckBox.value + '\r' + dlg.grpStuff.ddDropDown.selection.text ); } break; default: alert('bad number dude'); throw(Error('bad number dude')); }