-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstopBonsai.m
78 lines (68 loc) · 2.19 KB
/
stopBonsai.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function returnValue = stopBonsai()
%STOPBONSAI Stop currently running Bonsai workflow and close Bonsai
%
% Synopsis:
% ---------
% retVal = stopBonsai();
%
% Arguments:
% ----------
% -none
%
% Output:
% -------
% A string indicating the action:
% - 'Stop': All commands were executed without error and Bonsai should have stopped
% - 'Error': Something went wrong and Bonsai might not have been stopped
%
% Additional Information:
% -----------------------
% This script makes use of the Windows Script Host to start Bonsai. For ore
% information, please see following references:
% - Reference (Windows Script Host):
% https://docs.microsoft.com/en-us/previous-versions//98591fh7%28v%3dvs.85%29
% - Methods (Windows Script Host):
% https://docs.microsoft.com/en-us/previous-versions//2x3w20xf%28v%3dvs.85%29
% - AppActivate Method
% https://docs.microsoft.com/en-us/previous-versions//wzcddbek%28v%3dvs.85%29
% - Run Method (Windows Script Host)
% https://docs.microsoft.com/en-us/previous-versions//d5fk67ky%28v%3dvs.85%29
% - SendKeys Method
% https://docs.microsoft.com/en-us/previous-versions//8c6yea83%28v%3dvs.85%29
%
%
% Author: Michael Wulf
% Cold Spring Harbor Laboratory
% Kepecs Lab
% One Bungtown Road
% Cold Spring Harboor
% NY 11724, USA
%
% Date: 04/26/2019
% Version: 1.0.0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
returnValue = 'Stop';
try
% Get an instance of scripting shell
hndlWScript = actxserver('WScript.Shell');
% Wait a bit
pause(0.5);
% Bring Bonsai to foreground
hndlWScript.AppActivate('Bonsai');
% Send hotkey to stop workflow
hndlWScript.SendKeys('+{F5}');
fprintf('Stopping workflow...\n');
% Wait a bit
pause(0.5);
% Bring Bonsai to foreground again
hndlWScript.AppActivate('Bonsai');
% Send hotkey to close Bonsai
hndlWScript.SendKeys('%{F4}');
fprintf('Closing Bonsai...\n');
catch ME
returnValue = 'Error';
warning('An error occured while trying to stop Bonsai...');
disp(ME.identifier);
disp(ME.message);
end
end