Oddity with simple Text Edit script on multiple machines

This is just a small part of a larger script:

tell application "TextEdit"
		set x to make new document
		set the text of x to advisoryInfo & " " & advisoryInfo2 & " " & advisoryInfo3
		save x in advisoryInfoFilePath
		close x
end tell

This is a slightly different version of the same portion of the larger script:

tell application "TextEdit"
		make new document
		set the text of document 1 to advisoryInfo & " " & advisoryInfo2 & " " & advisoryInfo3
		save document 1 in advisoryInfoFilePath
		close document 1
end tell

Neither of which work correctly on one of ten computers.

This part of the script works fine on 9 Mac’s at work, but on the tenth, the larger script pauses right here and prompts the user to save the text document manually. This is not good because it in turn cancels the rest of the script which is really the most important part.

All ten Macintosh’s are Dual 2 GHz with anywhere from 1 to 2 GB of RAM.
All ten are running Mac OS 10.4.8.
All versions of TextEdit are 1.4.
All versions of ScriptEditor are 2.1.1.

Why is this portion of the script working on all but one Mac?


if plain text (.txt) files are sufficient for your project,
it would be easier to use the built-in read/write data commands,
something like this

set thetext to advisoryInfo & " " & advisoryInfo2 & " " & advisoryInfo3
write_to_file from thetext into (advisoryInfoFilePath as string)

on write_to_file from |data| into target
		set open_target_file to open for access file target with write permission
		write |data| to open_target_file
		close access open_target_file
		return true
	on error
			close access file target
		end try
		return false
	end try
end write_to_file

Both of them fail for me too.

It’s probably your advisoryInfoFilePath, but you don’t show how you get that.


Well, you’re right about that, Kel - and neither did Google or developer.apple.com. What is an advisoryInfoFilePath?? :o

Hey, thanks for all the reply’s. As for advisoryInfoFilePath – it’s just a variable that points to a directory on our server. Remember – the entire script works just fine on every other computer that we’re running it on, except the one.

As far as Stefan K’s suggestion goes…
a) I actually do need the file to be .rtf
b) I can’t get that script to do anything for me

So why the heck is this script fine on 9 computers and then for 1 it just won’t do what it’s supposed to?
Once again – every computer is EXACTLY the same…same Mac, same OS, same TextEdit, same ScriptEditor, etc. All the machines in our department are built from a single image.

I’m going to look at it a bit before I leave here tonight. I’ll be sure to post an answer if I ever get one.

Just a quick update:

I’ve just gone and checked TextEdits preferences, and they are identical to the other Mac’s that I’m working on.

I also tried writing out ‘save document x in advisoryInfoFilePath’ and ‘close document x’ (which is just adding the word document before the variable x)

Can’t really figure why your code DOES work on the first 9 macs. I have 25 here at work and have tested 4 to no avail. I did find a workaround that may or may not work for you (see below). You’ll need to make sure your TextEdit Preferences have “Rich Text” selected for the Format and “Ignore rich text commands in RTF files” must be OFF.

tell application "TextEdit"
	set mydocument to make new document
	tell mydocument
		set the text of it to advisoryInfo & " " & advisoryInfo2 & " " & advisoryInfo3
		set path of it to "/Users/John/Desktop/Untitled 1.rtf" --put your path here as Unicode text
		save it
		close it
	end tell
end tell

Since that’s the destination for your document save, it should specify a file, not a directory. ‘Save’ will create a specified file if it doesn’t already exist.

John: I’ll have to try that this afternoon. Also, my prefs are already set the way you specified.

Nigel: You’re correct ‘advistoryInfoFilePath’ is a file name and the path to where it should be saved, which is dynamic depending on previous information entered in the script.

Thanks again for all the responses. Hopefully I can sort this out this evening.

So…I figured out what the problem is. The single mac that this script won’t run on is an intel based mac. I haven’t figured out the solution though. Any help?

Compile the script on the Intel machine or save it (on PPC) as application bundle.
Then you get a UB application

I’ve just tried saving as an app bundle on PPC and on Intel, neither worked.

hm, very strange.
TextEdit is known for some weird AppleScript behavior,
maybe it’s still worse on Intel machines.

Can you use BBEdit (Lite) or something similar,
which is more robust than TextEdit?

I suppose I could. I wouldn’t want to have two separate scripts for PPC and Intel though so I would have to rebuild the entire thing. Which is what I’ll have to do, I guess…

Use this.

tell application "TextEdit"
	make new document
	tell result
		set it's text to "1 2 3"
		save in advisoryInfoFilePath
	end tell
end tell

.while comparing these: [edited]

When using an alias, the script behaves as intended.

Edit: Correction, the script always behaves correctly when the file already exists (regardless of the variable’s class).

Edit: Also, you’ll want to make sure TextEdit is set to make RTF files by default.

Model: MBP (Core 2 Duo, 15")
AppleScript: 1.10.7
Operating System: Mac OS X (10.4.8)

Were there any more problems with this?

I haven’t quite figured it out yet…

I working on a few other scripts for our workflow right now so I haven’t had the time to play around with it just yet. I’m also going to convert it to an application with applscript studio – hopefully that will help fix the issue, and if it doesn’t, I’ll rebuild the script with textwrangler. It seems that these are about my only options at this point.

Just a thought… not sure what the rest of the script does, but you mentioned earlier all your machine’s are from the same image. Just wanted to point out this is unlikely if you only have a small number of intel macs as PPC images and Intel images are not directly compatiable. You can make one work on both, but it’s a pain… so perhaps there is some small difference in the config that is causing earlier problems/inconstancies in yoru script which is blowing it up later.