Get SD's Editor colors

I see I can get all the AppleScript formatting records with

    tell application "Script Debugger"
	set theFormats to every AppleScript format
    end tell

But how about the Editor colors that appear just above this in the Fonts & Colors Prefs pane? Is there any way I can get these (and for that matter, any of the other formatting options lower down on that same panel)?

I’m trying to get the whole lot so that I can export it as a workaround ‘theme’, and then import it into another instance of SD.

If you change any of them from defaults, they’ll be in user defaults – the names are pretty obvious. You can see defaults like this:

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

NSUserDefaults's standardUserDefaults()'s dictionaryRepresentation()

So you should be able to write a script that reads them and writes the values to a property list, ready for import into another copy.

1 Like

Ah, of course. Cool. And that’s handy for another reason, I’ve just discovered.

It seems that SE shares the text colourings with SD (but not the background), so when switching between the two I’ll need to run a script to set the colours back to something readable in SE.

BTW, I know y’all will hate this cos you’re not used to it, but this is more or less how I’ve got all my other editors set up, so it looks natural to me:

I was trying to expose Script Debugger’s various color preference values to AppleScript but the suckyness of Cocoa Scripting asserted itself once again. It turns out that Cocoa Scripting does not support the notion of a color with an alpha channel, which Script Debugger uses for some of the editor colors which are overlaid (current line, error line, etc.) over the background color.

1 Like

There are 9 color settings in the Fonts & Colors pane aside from the 18 AppleScript formatting colors.

I can only find 6 8 of the 9:

PrefEditorBackgroundColor == Background
PrefEditorCursorColor == Insertion Point
PrefErrorLineColor == Error Line Highlight
PrefTabStopsCursorColor == Tab Stops
PrefCurrentLineColor == Current Line Highlight
PrefSelectionCursorColor == Selection

EDIT: Also found:

PrefEditorLineHighlightColor – Insertion Line Highlight
PrefHighlightMethodColor – Apply color to method and handler names

Not sure about this one though:
– Plain text formatting

This looks really helpful.

What was the final script and formats.txt file that you used to configure your color settings?

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):

20

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 :roll_eyes:

(*
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

Wow, this is fantastic! Thanks for sharing this with me and the rest of the community.

I’ll give it a try tonight.