Crikey, that’s a good question! I set this up 2 years ago and it’s worked reliably ever since, but I’m sure there is a much, much better way of doing it.
Anyway, I run the script below out of FastScripts, which produces a dialog like so for toggling (SE usually needs to be quit first, but SD seems able to cope with the change while running):
In the script, you’ll see a reference to a text file, “com.latenightsw.formats.txt”, which I have saved in the ~/Library/Preferences folder. It contains this (see EDIT below) for the SD formatting (triple-click the line to select the whole lot):
{{class:AppleScript format, font:"Courier", index:1, color:{65535, 65535, 26214}, name:"New text (uncompiled)", size:18}, {class:AppleScript format, font:"Verdana", index:2, color:{65535, 52428, 26214}, name:"Operators, etc. (+ & ,)", size:18}, {class:AppleScript format, font:"Verdana-Bold", index:3, color:{65535, 26214, 26214}, name:"Language keywords", size:18}, {class:AppleScript format, font:"Verdana-Bold", index:4, color:{0, 65535, 65535}, name:"Application keywords", size:18}, {class:AppleScript format, font:"Verdana-Italic", index:5, color:{19660, 19988, 19988}, name:"Comments", size:18}, {class:AppleScript format, font:"Verdana", index:6, color:{65535, 65535, 65535}, name:"Values (numbers, data)", size:18}, {class:AppleScript format, font:"Verdana", index:7, color:{0, 65535, 0}, name:"Variables and subroutine names", size:18}, {class:AppleScript format, font:"Verdana", index:8, color:{65535, 65535, 65535}, name:"Strings", size:18}, {class:AppleScript format, font:"Verdana-Bold", index:9, color:{0, 32896, 65535}, name:"Command names", size:18}, {class:AppleScript format, font:"Verdana", index:10, color:{59110, 59110, 59110}, name:"Parameter names", size:18}, {class:AppleScript format, font:"Verdana-Italic", index:11, color:{59110, 59110, 59110}, name:"Classes", size:18}, {class:AppleScript format, font:"Verdana", index:12, color:{65535, 65535, 26214}, name:"Properties", size:18}, {class:AppleScript format, font:"Verdana", index:13, color:{52428, 65535, 26214}, name:"Enumerated values", size:18}, {class:AppleScript format, font:"Verdana-Bold", index:14, color:{26214, 65535, 65535}, name:"Addition Command names", size:18}, {class:AppleScript format, font:"Verdana", index:15, color:{26214, 65535, 65535}, name:"Addition Parameter names", size:18}, {class:AppleScript format, font:"Verdana-Italic", index:16, color:{26214, 65535, 65535}, name:"Addition Classes", size:18}, {class:AppleScript format, font:"Verdana", index:17, color:{32896, 65535, 0}, name:"Addition Properties", size:18}, {class:AppleScript format, font:"Verdana", index:18, color:{32896, 65535, 0}, name:"Addition Enumerated values", size:18}}
I made a copy of the SE prefs pllist, `com.apple.applescript copy’ and saved that in the same place.
I think that’s all I did to set it up, but let me know if you can’t get it to work. It’s a long time ago, and of course, I didn’t bother leaving myself any notes or comments in the script…@badscripter
(*
Toggle between default Script Editor applescript formats and saved custom formats.
*)
use AppleScript version "2.4" -- Yosemite (10.10) or later
--use framework "Foundation"
use scripting additions
set theChoice to ""
set SEIsRunning to missing value
set SDIsRunning to missing value
set SEPlist to "com.apple.applescript" -- Script Editor formatting
set SDPlist to "com.latenightsw.ScriptDebugger6" -- SD6 formats
set theMsg to "To use SD6 custom format, choose 'Dark'." & return & "To use Script Editor text sizes & colours, choose 'Light'."
set theChoice to button returned of (display dialog theMsg buttons {"Cancel", "Dark", "Light"} default button "Light" with icon 1 with title "AppleScript Formats")
if theChoice is "Light" then
--SE
set originalPlist to SEPlist
else
--SD6 Dark
set the_file to (((path to preferences from user domain) as text) & "com.latenightsw.formats.txt")
set theFormatRecs to (read file the_file as list)
tell application "Script Debugger"
repeat with i from 1 to count of theFormatRecs
set theProps to theFormatRecs's item i
tell AppleScript format i
set its font to theProps's font
set its size to theProps's size
set its color to theProps's color
end tell
end repeat
end tell
set originalPlist to SDPlist
end if
set duplicatePlist to originalPlist & "\\ copy"
set theContents to (do shell script "defaults read " & duplicatePlist)
try
do shell script "defaults write " & originalPlist & space & quoted form of theContents
end try
.
EDIT: ah, looking at my own screenshot above, it looks like what I did to create the com.latenightsw.formats.txt
was set up all the colours manually in SD’s Preferences first, then saved them by running the following script. Obviously I changed the name and location later.
I don’t know if just copying the list I pasted above into a text file works or not, but might be worth a try to save time, unless you want to adjust the formatting to your own taste of course, in which case use this:
(*
Capture Script Debugger's current applescript formats to a text file
*)
use AppleScript version "2.4" -- Yosemite (10.10) or later
# use framework "Foundation"
use scripting additions
-- classes, constants, and enums used
# property NSUserDefaults : a reference to current application's NSUserDefaults
set formatRecord to {}
tell application "Script Debugger"
set theFormats to every AppleScript format
repeat with i from 1 to count of theFormats
set theFormatProps to properties of item i of theFormats
set end of formatRecord to theFormatProps
end repeat
end tell
set the_file to ((path to desktop as text) & "formats.txt") as «class furl»
try
set dataStream to open for access the_file with write permission
set eof of dataStream to 0
write formatRecord to dataStream starting at eof as list
close access dataStream
on error
try
close access the_file
end try
end try
# set theDefaults to NSUserDefaults's standardUserDefaults()'s dictionaryRepresentation()
# PrefEditorBackgroundColor == Background
# PrefEditorCursorColor == Insertion Point
# PrefErrorLineColor == Error Line Highlight
# PrefTabStopsCursorColor == Tab Stops
# PrefCurrentLineColor == Current Line Highlight
# PrefSelectionCursorColor == Selection
#
# The one's I'm missing are
#
# PrefEditorLineHighlightColor -- Insertion Line Highlight
# PrefHighlightMethodColor -- Apply color to method and handler names
# -- Plain text formatting