Determine if current script is running in Script Debugger, with debugging enabled

Is there a better way to do this?

When I am debugging a script using Myriad Tables I used to manually set a debugging variable to true, and then MT is run in a separate app. When I turn off debugging it runs MT from within the script, which it also does when run live as an applet or from a scripts menu.

Now, I’m using the handler below to set that variable, but it seems rather clunky and I’m not sure how reliable it will be.

Is there a better way to tell if the current script that is executing is in Script Debugger with Debugger enabled? (That is the only context where I would use the separate app).

set debugging to IsThisScriptRunningWithDebuggingEnabled()

on IsThisScriptRunningWithDebuggingEnabled()
   tell application "System Events"
      try
         set sdRunning to exists (application process 1 whose name is "Script Debugger")
      on error
         set sdRunning to false
      end try
      if not sdRunning then
         set debugging to false
         return debugging
      end if
      --application process "Script Debugger" 
   end tell
   tell application "Script Debugger"
      set myPath to (path to me as text)
      set myFileSpec to (get file spec of front document)
      --» If THIS script document is FRONTMOST  check if debugging is enabled
      if myFileSpec is missing value then -- new, unsaved script is running in SD  
         set runningScript to a reference to document 1
      else if myPath = (myFileSpec as text) then
         set runningScript to a reference to document 1
      else
         set debugging to false
      end if
      tell runningScript
         set debugging to debugger enabled
      end tell
   end tell
   return debugging
end IsThisScriptRunningWithDebuggingEnabled

→ Mac OS: 14.6.1 (23G93)
→ Script Debugger 8.0.10 (8A88)
→ SD Notary 2 2.0 (102)
→ FastScripts 3.3.4 (1910)

You can easily get AppleScript runtime name from AppleScript.

http://piyocast.com/as/archives/9004

1 Like

Hi @estockly,

Here is my suggestion:

set SD to "Script Debugger"
if application SD is not running or name of current application ≠ SD then return false
tell application SD to return debugger enabled of front document

We have been using this for years. Thanks to Ray Robertson for it:

–» Set DevMode OFF/ON
set thisName to “”
set devMode to false
try
set propsRecord to properties of me
set thisName to name of propsRecord
end try
if thisName contains “Debugger” then
set devMode to true
end if

set devMode to true

set devMode to false

The commented out lines at the end allow us to quickly override it for testing purposes.