How Do I Create New Script Window in SD7?


(Jim Underwood) #1

OK, back in SD6, we had some issues, but this script did open a NEW window:

tell application "Script Debugger"
  set fileToOpen to POSIX path of (path to documents folder) & "Test/@TEST open window.scpt"
  
--- Creates New Window with Empty doc in Tab 1 ---
  set oDoc to (make new document)

end tell

However, it just opens a new TAB in Script Debugger 7 7.0.3 (7A55) on macOS 10.12.6, or if run from Script Editor.

So, how do I get a NEW window in SD7 without resorting to System Events UI scripting?

Thanks.

REF: How Do I Move Script Document to New Window?


(Shane Stanley) #2

Scripting now follows your preferences setting for Open in Tabs. So to ensure you open in a new window, do something like this:

	set tabsSetting to open in tabs
	set open in tabs to no
	set oDoc to (make new document)
	set open in tabs to tabsSetting

(Jim Underwood) #3

Thanks, Shane. That did the trick! :+1:

To help others who may be interested in this subject, I’ll share my test/proof-of-concept script showing ways to open a script in a new window in SD7:

Open Script in New Window in SD7

set fileToOpen to POSIX path of (path to documents folder) & ¬
  "Test/@TEST open window.scpt"
set oFile to POSIX file fileToOpen

tell application "Script Debugger 7"
  
  ----------------------------------------------------
  --- This is KEY to Opening Script in New Window ---
  ----------------------------------------------------
  set open in tabs to no
  
  --- Opens File in New Window IF "open in tabs" is no ---
  open fileToOpen
  --  return
  
  set pScriptStr to "
      tell application \"Finder\"
      
      end tell
      "
  --- Opens Script Text in New Window ---
  set oDoc to make new document with properties {source text:pScriptStr, debugger enabled:false}
  tell oDoc to compile
  
  return
  
  set newWin to script window 1 of oDoc
  --- Opens File in Tab 2 ---
  open fileToOpen in window newWin
  
  
  ### THIS FAILS ###
  # set oDoc to make new document with properties {file spec:oFile, debugger enabled:false}
  # open fileToOpen in new window
  # open fileToOpen in window (new window)
  # open fileToOpen in window (make new window)
  
  
end tell



(Ed Stockly) #4

One suggestion, get the value of the open in tabs preference first, then reset it after you open the script.

That way the preference doesn’t change whenever you run the script.

tell application "Script Debugger"
   
   ----------------------------------------------------
   --- This is KEY to Opening Script in New Window ---
   ----------------------------------------------------
   set intialOpenInTabsState to open in tabs
  
     set open in tabs to n

       --open your script

    set open in tabs to intialOpenInTabsState  
end tell

(Jim Underwood) #5

Yep, I knew that, and left the get/restore out on purpose.
Shane showed the get/restore.

I just hate using 3 commands where I only need one.
It appears to me that the preference does not affect the UI commands of ⌘N and ⌘T, which is good. They only affect script commands. So, I would never assume a given preference, and thus always issue the set open in tabs command every time.

This is the same issue as with the set AppleScript's text item delimiters.

When I put such statements in a handler, then I do use the get/restore technique.


(Shane Stanley) #6

Plus what happens if you double-click a script.


(Jim Underwood) #7

Not sure what you mean. When I double-click a script file it opens in SD7.


(Shane Stanley) #8

If you have Open in Tabs checked and a window already open, double-clicking on a file will open it as a tab of that window. If it’s unchecked, it will open in its own window. So the preference affects more than scripting.