Unix Newlines in Script Debugger
I recently had a customer struggling to embed multi-line Unix shell scripts within their AppleScript script using Script Debugger.
The problem is that Script Debugger’s default Newline character is CR (ASCII 13). This is a historical relic dating back to the Classic Mac OS days. When Apple introduced Script Editor 2, they changed the default newline from CR to LF. We chose to stay with CR to avoid breaking existing scripts.
This choice to remain with CR causes Script Debugger to operate differently from the Script Editor when editing multi-line string literals. This is particularly a problem when you are trying to embed multi-line Unix scripts (sh, perl, ruby, python, etc.) which expect LF newlines into an AppleScript script.
Fortunately, there is a solition. You can change Script Debugger’s default Newline character using the following terminal command (make sure you quit Script Debugger before issuing it):
defaults write com.latenightsw.ScriptDebugger PrefEditorNewLineIsCR -bool no
Once this command has been issued, Script Debugger will insert LF characters whenever you press return. When the newline character matters to you, I recommend also using the Show Invisibles command (View menu) to make Script Debugger show you the newline characters
One final note: AppleScript converts LF newlines to CR in text outside string literals and block commands when scripts are compiled or opened. Here again, Script Debugger’s Show Invisibles feature will make it clear which newline character is being used where.