Launching an app from Applescript

've written a little Applescript that writes to a file’s .plist file, launches the app, and quits.

the problem I have is that the AppleScript doesn’t seem to quit, and so the menubar doesn’t seem to appear on the app it is launching (it appears if the app is launched normally). It seems the AppleScript isn’t giving hand to the app.

Any help would be greatly appreciated, I’m barely beginning here…

here’s the code:


on run {}
	
	set this_story to "<dict>
	<key>SplashOrNot</key>
	<string>NO</string>
	<key>LanguageOfChoice</key>
	<string>Francais</string>
	<key>CardNumber</key>
	<string>Reticulaires</string>
	<key>NavigationOrNot</key>
	<string>NO</string>
</dict>
</plist>"
	set this_file to (((path to preferences folder) as text) & "diff.plist")
	my write_to_file(this_story, this_file, false)
	try
		tell application "diff2"
			run
		end tell
	end try
end run

on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as text
		set the open_target_file to ¬
			open for access file target_file with write permission
		if append_data is false then ¬
			set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file

Just in case… Seems that the plist you write to the pref file is not a valid plist file. I miss these lines before the “” tag:

<?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">

It this doesn’t fix your problem… Does the app launch OK if you don’t write the plist file? (you send only the run command)

If (true) perhaps the app can’t read properly the new plist you wrote. The “returns” you write… Are Line Feeds or Carriage Returns?

I know I’m missing those lines, but I can’t get AppleScript to write them to the file. It freaks out with the numbers and the quotes in those lines, says it found a real number where it was looking for an end of line. Perhaps you can help me out with this problem too :wink:

The thing is, if I write the .plist with the AppleScript, and then manually launch the app, everything is fine. If however I include the run command, then the applescript kind of hangs, and doesn’t quit, and the app is also somehow affected in that it doesn’t display it’s menu.

You can include quotes and other special characters in a string “escaping” them. For example, try this:

display dialog """
display dialog "\"

What if you use “launch application whatever” instead of sending a “run”?