# Use ScriptWriter with MyToolbar Example

**URL:** <https://forum.universal-robots.com/t/use-scriptwriter-with-mytoolbar-example/14368>\
**Category:** URCap Development\
**Created:** [May 18, 2021, 9:52am UTC](https://forum.universal-robots.com/t/use-scriptwriter-with-mytoolbar-example/14368 "2021-05-18T09:52:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon12657279](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@anon12657279](https://forum.universal-robots.com/u/anon12657279)\
**Post date:** [May 18, 2021, 9:52am UTC](https://forum.universal-robots.com/t/use-scriptwriter-with-mytoolbar-example/14368/1 "2021-05-18T09:52:55Z")

</div>

Hello,

I wanted to try to modify the example “my toolbar” and added a button (with Swing) that will trigger a script, but i’m stuck.  
I’m having trouble understanding the use of ScriptWriter.  
if I try to take the example with the generateScript () method. I have an error telling me:  
_The method generateScript(ScriptWriter) of type MyToolbarContribution must override or implement a supertype method_

Can you help me run a script when pressing the button please ?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [May 18, 2021, 3:14pm UTC](https://forum.universal-robots.com/t/use-scriptwriter-with-mytoolbar-example/14368/2 "2021-05-18T15:14:32Z")

</div>

I could be wrong but I don’t think you need a generateScript() method in the toolbar contribution. Assuming you are using the ScriptCommand and ScriptSender classes, the following code is something I use to jog the robot from the toolbar:

movePose1.addMouseListener(new MouseAdapter() {

```
		@Override
		public void mousePressed(final MouseEvent e) {
			if(movePose1.isEnabled()) {
				//create a new instance of the ScriptCommand class
				final ScriptCommand moveJ = new ScriptCommand();
				//create a new String to hold the command
				String string = "movej(" + getFavPose1().toString() + ", a=1.4, v=0.30, t=0, r=0)";
				//assign the newly created command as Primary. Secondary commands cannot consume robot time
				moveJ.setAsPrimaryProgram();
				//add the created string to the command
				moveJ.appendLine(string);
				//create a new instance of a ScriptSender
				final ScriptSender sender = new ScriptSender();
				//send the created script using the newly created sender
				sender.sendScriptCommand(moveJ);
			}
		}

		@Override
		public void mouseReleased(final MouseEvent e) {
			if (movePose1.isEnabled()) {
				
				final ScriptCommand stopj = new ScriptCommand();
				String string = "stopj(2)";
				stopj.setAsPrimaryProgram();
				stopj.appendLine(string);
				
				final ScriptSender sender = new ScriptSender();
				sender.sendScriptCommand(stopj);
			}
		}
	});

```

I don’t remember exactly where I found these 2 classes. They were somewhere on the forum I think.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/system/32/1_2.png) [@system](https://forum.universal-robots.com/u/system)\
**Post date:** [May 20, 2021, 3:15pm UTC](https://forum.universal-robots.com/t/use-scriptwriter-with-mytoolbar-example/14368/3 "2021-05-20T15:15:17Z")

</div>

Closed on May 20, 2021, 3:15pm UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
