How to know that the script is running in Debug?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Massimo
Newbie
Posts: 10
Joined: Sat Dec 28, 2019 5:16 pm

How to know that the script is running in Debug?

Post by Massimo » Tue May 10, 2022 6:34 am

Any one knows if there is a method to know that the script is running in debug mode?
I need to change the behavior of my program in function of this.
For sure I could set a variable to True or False, but it would be great if this could be evaluated automatically by testing a system variable :D

Thanks
Massimo

User avatar
Grovkillen
Automation Wizard
Posts: 796
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: How to know that the script is running in Debug?

Post by Grovkillen » Tue May 10, 2022 9:47 am

You can look at the command line variable and see what process it is running from.
Let>ME=%Script%

Running: 15.0.20
version history

User avatar
Massimo
Newbie
Posts: 10
Joined: Sat Dec 28, 2019 5:16 pm

Re: How to know that the script is running in Debug?

Post by Massimo » Tue May 10, 2022 12:02 pm

Thanks, very simple :D
However I had to change in:

Let>Me=%COMMAND_LINE%

Result:
Me="C:\Program Files (x86)\Macro Scheduler 15\msched.exe"

User avatar
JRL
Automation Wizard
Posts: 3435
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: How to know that the script is running in Debug?

Post by JRL » Tue May 10, 2022 8:43 pm

Am I missing something here?

Is not "running in debug" simply another way of saying "running in the editor"? In my experience no matter how you run a non-compiled script the command_line variable will always be installed_directory\msched.exe. That includes running in the editor. The only way I am aware to determine whether you are running in the editor is to check if the current window is "Macro - ScriptName". If the current window is "Macro - ScriptName", you in Debug or running in the editor.

Code: Select all

ExtractFileName>Script_name,fName,1
GetActiveWindow>WinTitle,WinX,Winy
Let>TestName=Macro - %FName%

If>{(%WinTitle%=%TestName%)or(%script_Name%="__debug.dbg")}
  Let>Debug_Mode=True
Else
  Let>Debug_Mode=False
EndIf

MDL>Debug_Mode

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1070
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: How to know that the script is running in Debug?

Post by Dorian (MJT support) » Tue May 10, 2022 9:04 pm

JRL wrote:
Tue May 10, 2022 8:43 pm
Am I missing something here?

Is not "running in debug" simply another way of saying "running in the editor"? In my experience no matter how you run a non-compiled script the command_line variable will always be installed_directory\msched.exe. That includes running in the editor. The only way I am aware to determine whether you are running in the editor is to check if the current window is "Macro - ScriptName". If the current window is "Macro - ScriptName", you in Debug or running in the editor.

Code: Select all

ExtractFileName>Script_name,fName,1
GetActiveWindow>WinTitle,WinX,Winy
Let>TestName=Macro - %FName%

If>{(%WinTitle%=%TestName%)or(%script_Name%="__debug.dbg")}
  Let>Debug_Mode=True
Else
  Let>Debug_Mode=False
EndIf

MDL>Debug_Mode
I was thinking along the same lines as you too. The previous solution would identify if it was a compiled script or being run by Macro Scheduler.

This was my effort.

Code: Select all

GetActiveWindow>window_title,XX,YY
Pos>%script_name%,window_title,1,Open,

If>Open>0
  mdl>Open in debugger
else
  mdl>NOT open in debugger
Endif
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
JRL
Automation Wizard
Posts: 3435
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: How to know that the script is running in Debug?

Post by JRL » Tue May 10, 2022 9:43 pm

Glad you agree. Its always worrisome not quite knowing what others are thinking. Not that I haven't had to pull my foot out of my mouth hundreds of times before. Still, strive for "accuracy".

I would add to your "If>" line to catch the possibility of not yet having saved/named the new macro.

Code: Select all

GetActiveWindow>window_title,XX,YY
Pos>%script_name%,window_title,1,Open,

If>{(%Open%>0)or(%window_title%="Macro - ")}
  mdl>Open in debugger
else
  mdl>NOT open in debugger
Endif

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1070
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: How to know that the script is running in Debug?

Post by Dorian (MJT support) » Tue May 10, 2022 10:21 pm

Aaah, good point! Thank you!
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts