Files are saved with CR line endings

Script Debugger now saves text-based AppleScript files with CR line endings. The opened file was saved with LF line endings. I think this just changed, when I updated to version 7.0.11.

Additional info: my Editor preferences says Unix (LF) as New Line Character. I did open an 'scpt` file from some other user. Maybe that triggered this?

Save as, and choose LF + Replace still saves the file with CR. As work around I can use Textmate to convert to LF endings before I check in to git, but that’s not ideal.

I’m on macOS Mojave 10.14.6 (18G4032). And I just added Script Debugger to Full Scripting Access, because it asked me to.

Update: can I download the previous version of Script Debugger, because this is a real hassle…

This is a regression that slipped in with the changes to work around the Catalina save problems. It will be fixed in an upcoming version. You can download 7.0.10 here:

SD 7.0.10

One other point: the files are being saved using As Is, not CR. You’re seeing CR where the compiler puts them, but any LFs (such as in quotes or uncompiled text) will be retained.

This means you can change them all in Script Debugger before saving. For example, you could run a script like this:

tell application id "com.latenightsw.ScriptDebugger7" -- Script Debugger.app
	tell document 1
		set theText to source text
		set {saveTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {return}}
		set theItems to text items of theText
		set AppleScript's text item delimiters to {linefeed}
		set theText to theItems as text
		set AppleScript's text item delimiters to saveTID
		set source text to theText
		-- optionally save the changes
		save
	end tell
end tell

Give it a shortcut, and you can use it as an alternative save command. If you’re on Catalina, that’s probably a more reliable approach.

I get this error when downloading via the above link:

<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>079A1D05A46A5355</RequestId>
<HostId>
b4SRf82lR8qpmo+nwX0sF6B22FU5PzJF2c5cVYRpk34wEVUihojedhblYaezQzxGUrtWqS6PvB8=
</HostId>
</Error>```

I’ve corrected the link above.

1 Like

I’ve run into the same ‘trap’ and got problems in Xcode - as always Shane helped and sent me here.

I’ve a real lot of files affected so maybe this little script below might be of help for those who also have to change a lot of files.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

property cA : a reference to current application

property fileList : {}
property txCheck : {}
property parList : {}

on open fileList
	repeat with i from 1 to the count of fileList
		set thePath to item i of fileList
		set zKind to (kind of (info for thePath)) as text
		if zKind = "Text OSA Script" then
			my processFile(thePath)
		end if
	end repeat
end open

on processFile(theFilePath)
	try
		set theFilePath to POSIX path of theFilePath
		set txCheck to (read theFilePath) as text
		set my parList to (every paragraph of txCheck)
		set txCheck to my listToString(parList, string id 10)
		set tmpEntry to (cA's NSString's stringWithString:txCheck)
		(tmpEntry's writeToFile:theFilePath atomically:true encoding:(cA's NSUTF8StringEncoding) |error|:(missing value))
	on error errMsg
		log errMsg
		return 0
	end try
end processFile

on listToString(theList, theDelimiter)
	set anArray to cA's NSArray's arrayWithArray:theList
	set someString to (anArray's componentsJoinedByString:(theDelimiter)) as string
	return someString
end listToString