How to display proper xml code in the applescript editor

Hi,
I’m writing a few scripts to make and install launch agents in the user library. As a template for the first script, I used an older script by StefanK. Thank you Stefan.

My problem was that when I opened the script in my editor and saved it to my Mac, the xml part of it changed from


set PLIST_File to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
	<key>Label</key>
	<string>" & pListLabel & "</string>
	<key>LowPriorityIO</key>
	<true/>
	<key>Program</key>
	<string>/usr/bin/osascript</string>
	<key>ProgramArguments</key>
	<array>
		<string>osascript</string>
		<string>" & POSIX path of triggeredScriptLocation & triggeredScriptName & "</string>
	</array>
	<key>StartCalendarInterval</key>
	<dict>
		<key>Hour</key>
		<integer>" & hr & "</integer>
		<key>Minute</key>
		<integer>" & mn & "</integer>
	</dict>
</dict>
</plist>
"

to


set PLIST_File to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n\t<key>Label</key>\n\t<string>" & pListLabel & "</string>\n\t<key>LowPriorityIO</key>\n\t<true/>\n\t<key>Program</key>\n\t<string>/usr/bin/osascript</string>\n\t<key>ProgramArguments</key>\n\t<array>\n\t\t<string>osascript</string>\n\t\t<string>" & POSIX path of triggeredScriptLocation & triggeredScriptName & "</string>\n\t</array>\n\t<key>StartCalendarInterval</key>\n\t<dict>\n\t\t<key>Hour</key>\n\t\t<integer>" & hr & "</integer>\n\t\t<key>Minute</key>\n\t\t<integer>" & mn & "</integer>\n\t</dict>\n</dict>\n</plist>\n"

That makes editing the xml code practically impossible, unless one wants to get crossed eyes.

So, I had to run Stefan’s script to create and install his launch agent plist file (which I didn’t really need), then open that plist file in a plist editor (I’m using PlistEdit Pro, which can display the corresponding xml code as well), edit the plist to do what I needed, and then pasted the final xml code in my applescript, modified to make and install the desired plist file.

It worked, but it is very cumbersome. I’d have to repeat this process for any new launch agent plist (or any other plist installer) containing different xml code. There must be a better way, is saying my optimist side.

Is there any way to display proper editable xml code in the applescript editor? I’d be grateful for any help.

I haven’t tinkered enough with it, but it seems to me that this is hard to achieve with AppleScript Editor.

How about leaving a copy of the xml inside a comment?

Hi,

in AppleScript Editor open Preferences > Editing and deselect “Escape tabs and line breaks in strings”

Thanks again Stefan.
My optimistic side was right - there was a better way, a much better and easy way :cool:
I’m quite embarrassed to have missed that pref setting :frowning: