Index: TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/Application.java
===================================================================
--- TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/Application.java	(revision 3636)
+++ TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/Application.java	(revision 3637)
@@ -311,10 +311,10 @@
 				}
 				
 				if (argsList.contains("--action=new")) {
-					String path = argsList.get(argsList.size() -2);
+					String path = argsList.get(argsList.indexOf("--action=new") + 1);
 					File sourcePath = new File(path);
 					
-					String name = argsList.get(argsList.size() -1);
+					String name = argsList.get(argsList.indexOf("--action=new") + 2);
 					
 					ret = doNew(sourcePath, name);
 					
@@ -339,7 +339,7 @@
 				} else if (argsList.contains("--action=groovy")) {
 					
 					
-					String path = argsList.get(argsList.size() -1).trim();
+					String path = argsList.get(argsList.indexOf("--action=groovy") + 1).trim();
 					
 					ret = doGroovy(path, argsList);
 				} else if (argsList.contains("--action=R")) {
@@ -370,7 +370,15 @@
 		if (!script.isFile()) return -1;
 		if (!script.exists()) return -1;
 		if (!script.getName().endsWith(".groovy")) return -1;
-		ExecuteScript.executeScript(path, null, new StructuredSelection(), argsList);
+		try {
+			JobHandler job = ExecuteScript.executeScript(path, null, new StructuredSelection(), argsList);
+			if (job != null) {
+				job.join();
+			}
+		} catch(Throwable e) {
+			e.printStackTrace();
+			return -1;
+		}
 		return 0;
 	}
 	
@@ -380,13 +388,22 @@
 		if (!script.isFile()) return -1;
 		if (!script.exists()) return -1;
 		if (!script.getName().endsWith(".R")) return -1;
+		
 		EnginesManager<? extends Engine> em = Toolbox.getEngineManager(EngineType.STATS);
 		if (em == null) return -1;
 		
 		Engine e = em.getEngine("R");
 		if (e == null || !e.isRunning()) return -1;
 		
-		ExecuteScript.executeScript(path, null, new StructuredSelection(), argsList);
+		JobHandler job = ExecuteScript.executeScript(path, null, new StructuredSelection(), argsList);
+		if (job != null) {
+			try {
+				job.join();
+			} catch (Throwable e1) {
+				e1.printStackTrace();
+				return -1;
+			}
+		}
 		
 		return 0;
 	}
Index: TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyMacro.java
===================================================================
--- TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyMacro.java	(revision 3636)
+++ TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyMacro.java	(revision 3637)
@@ -52,6 +52,7 @@
 import org.txm.Toolbox;
 import org.txm.rcp.editors.TxtEditor;
 import org.txm.rcp.swt.dialog.LastOpened;
+import org.txm.rcp.utils.JobHandler;
 // TODO: Auto-generated Javadoc
 /**
  * Handler: execute a Macro (Groovy script that opens an UI for parameters)
@@ -120,7 +121,7 @@
 		return execute(result, page, selection, stringArgs, null, null);
 	}
 	
-	public static IStatus execute(String scriptpath, IWorkbenchPart page, ISelection selection, List<String> args, HashMap<String, Object> parameters, HashMap<String, Object> defaultParameters) {
+	public static JobHandler execute(String scriptpath, IWorkbenchPart page, ISelection selection, List<String> args, HashMap<String, Object> parameters, HashMap<String, Object> defaultParameters) {
 		//IPreferencesService service = Platform.getPreferencesService();
 		String scriptRootDir = Toolbox.getTxmHomePath() + "/scripts"; //$NON-NLS-1$
 		File currentRootDir = new File(scriptRootDir, "groovy/user"); //$NON-NLS-1$
Index: TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyScript.java
===================================================================
--- TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyScript.java	(revision 3636)
+++ TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteGroovyScript.java	(revision 3637)
@@ -156,7 +156,7 @@
 	 * @param sel current selection, might be null
 	 * @return 
 	 */
-	public static IStatus executeScript(String scriptpath, final  IWorkbenchPart page, final ISelection selection, boolean modal, String stringArgs) {
+	public static JobHandler executeScript(String scriptpath, final  IWorkbenchPart page, final ISelection selection, boolean modal, String stringArgs) {
 		IPreferencesService service = Platform.getPreferencesService();
 		//		String scriptRootDir = service.getString(Application.PLUGIN_ID,
 		//				ScriptPreferencePage.SCRIPT_ROOT_DIR,
@@ -186,7 +186,7 @@
 	 * @param page current active page, might be null
 	 * @param sel current selection, might be null
 	 */
-	public static IStatus executeScript(String scriptpath, final  IWorkbenchPart page, final ISelection selection) {
+	public static JobHandler executeScript(String scriptpath, final  IWorkbenchPart page, final ISelection selection) {
 		return executeScript(scriptpath, page, selection, false, null);
 	}
 
@@ -197,12 +197,12 @@
 	 * @param page current active page, might be null
 	 * @param sel current selection, might be null
 	 */
-	public static IStatus executeScript(final File currentRootDir, String scriptpath, final  IWorkbenchPart page, final ISelection sel, final boolean modal, final List<String> stringArgs, HashMap<String, Object> parameters, HashMap<String, Object> defaultParameters) {
+	public static JobHandler executeScript(final File currentRootDir, String scriptpath, final  IWorkbenchPart page, final ISelection sel, final boolean modal, final List<String> stringArgs, HashMap<String, Object> parameters, HashMap<String, Object> defaultParameters) {
 		// check script
 		final File scriptfile = new File(scriptpath);
 		if (!scriptfile.exists()) {
 			Log.severe(NLS.bind(TXMUIMessages.p0ScriptFileDoesntExist, scriptpath));
-			return Status.CANCEL_STATUS;
+			return null;
 		}
 		ExecuteLastGroovyScript.setLastScript(scriptfile, currentRootDir.getName().equals("macro")); // register last groovy script //$NON-NLS-1$
 
@@ -231,7 +231,7 @@
 		String path = scriptfile.getAbsolutePath();
 		if (!path.startsWith(dir)) {
 			Log.severe(TXMUIMessages.bind(TXMUIMessages.theP1GroovyScriptMustBeInTheP0Folder, dir, path));
-			return Status.CANCEL_STATUS;
+			return null;
 		}
 		final String relativepath = path.substring(dir.length()+1);
 
@@ -280,7 +280,7 @@
 					} else {
 						Log.severe(TXMUIMessages.theUserCanceledTheScriptExecution);
 					}
-				} catch (Exception e) {
+				} catch (Throwable e) {
 					Log.severe(TXMUIMessages.errorDuringScriptExecutionColon+e);
 					e.printStackTrace();
 				} finally {
@@ -291,7 +291,7 @@
 		};
 		
 		jobhandler.startJob(modal);
-		return Status.OK_STATUS;
+		return jobhandler;
 		//        //gse.loadScriptByName("scripts/B.groovy");
 		//		gse.run("A.groovy", new Binding());
 
Index: TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteScript.java
===================================================================
--- TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteScript.java	(revision 3636)
+++ TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteScript.java	(revision 3637)
@@ -64,6 +64,7 @@
 import org.txm.rcp.messages.TXMUIMessages;
 import org.txm.rcp.preferences.RCPPreferences;
 import org.txm.rcp.swt.dialog.LastOpened;
+import org.txm.rcp.utils.JobHandler;
 import org.txm.utils.logger.Log;
 // TODO: Auto-generated Javadoc
 /**
@@ -187,10 +188,10 @@
 	 *
 	 * @param scriptpath the scriptfile
 	 */
-	public static IStatus executeScript(String scriptpath, final  IWorkbenchPart page, final ISelection selection, List<String> stringArgs) {
-		if (scriptpath == null) return Status.CANCEL_STATUS;
+	public static JobHandler executeScript(String scriptpath, final  IWorkbenchPart page, final ISelection selection, List<String> stringArgs) {
+		if (scriptpath == null) return null;
 		File script = new File(scriptpath);
-		if (!script.exists()) return Status.CANCEL_STATUS;
+		if (!script.exists()) return null;
 
 		String ext = script.getName();
 		int i = ext.lastIndexOf("."); //$NON-NLS-1$
@@ -207,12 +208,13 @@
 				HashMap<String, Object> env = new HashMap<String, Object>();
 				env.put("page", page); // selection //$NON-NLS-1$
 				env.put("selection", selection); // selection //$NON-NLS-1$
-				return se.executeScript(script, env, stringArgs);
+				se.executeScript(script, env, stringArgs); // TODO move JobHanddler to the Toolbox plugin
+				return null;
 			} else {
 				Log.warning(TXMUIMessages.noInterpreterFoundForScriptFileExtension+script.getName());
 			}
 		}
 		
-		return Status.CANCEL_STATUS;
+		return null;
 	}
 }
\ No newline at end of file
Index: TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/utils/JobHandler.java
===================================================================
--- TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/utils/JobHandler.java	(revision 3636)
+++ TXM/trunk/org.txm.rcp/src/main/java/org/txm/rcp/utils/JobHandler.java	(revision 3637)
@@ -29,14 +29,9 @@
 
 import java.util.concurrent.Semaphore;
 
-import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.jobs.ISchedulingRule;
 import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.internal.progress.ProgressManagerUtil;
-import org.eclipse.ui.texteditor.ISchedulingRuleProvider;
 import org.txm.rcp.Application;
 import org.txm.rcp.StatusLine;
 import org.txm.rcp.messages.TXMUIMessages;
