problem saving filename, called from read folder loop, using TextEdit

Hi folks,

this is my first post, so i’d like to say thanks to all those who have come before me - this site has been really useful in the last few days
I’ve almost finished my first applescript project and am really enjoying it.

as part of a larger program I need to call an Excel file {filename} from a folder, perform and action on them, copy the output to a TextEdit file, saving the text file as {filename}&“.txt”

everything is working fine except the last step, saving the file, where i get an error message as follows…

Error Message: The document “Untitled” could not be exported as “Chip_fur_mix_50kW.xls.txt”. The file does not exist.

now, I can see in the event log (below) that TextEdit is trying to save a file called

{“Macintosh HD:Sima_data:processing_tests:Macintosh HD:Sima_Data:raw_data copy:Chip_fur_mix_50kW.xls.txt”}

this is clearly not going to work but I am not sure how to get around it.,

( I should add that manually entering a value i.e. {set filename to “test_name_999.xls”} returns the desired result so I am guessing it has something to do with the way {filename} is stored as a reference to both the filename and source folders rather than as just the filename}

I hope someone else has experience with this kind of problem and could offer some advice,

cheers & thanks

Nic

  

set datafolder to choose folder
tell application "Finder"
	set fileList to every file of datafolder -- entire contents of folder
	repeat with filename in the fileList
		--set filename to "test_name_999.xls"
		open filename
		
		
		
		tell application "TextEdit"
			activate
			
			
			tell application "System Events"
				
				tell process "TextEdit"
					--activate
					
					keystroke "v" using {command down, shift down, option down} -- this ensure the format in excel is kept, allowing for data to be easily read later on (i.e., normal excel tab format)
					keystroke return -- this is essential to bring the next flow onto a new line. so simple but took a couple of hours to figure out
					keystroke return -- repeated to separate {info_range} and data
					
					
					
				end tell
			end tell
		end tell
		
		
		tell application "Microsoft Excel"
			close every workbook saving no -- closes and but doesn't save all open workbooks.
		end tell
		
	end repeat
end tell

tell application "TextEdit"
	activate
	
	save document "Untitled" in file {"Macintosh HD:Sima_data:processing_tests:" & filename & ".txt"}
end tell


Event Log (for last section)

tell application “Finder”
get document file “Chip_fur_mix_50kW.xls” of folder “raw_data copy” of folder “Sima_Data” of startup disk
“Macintosh HD:Sima_Data:raw_data copy:Chip_fur_mix_50kW.xls”
end tell
tell application “TextEdit”
save document “Untitled” in file {“Macintosh HD:Sima_data:processing_tests:Macintosh HD:Sima_Data:raw_data copy:Chip_fur_mix_50kW.xls.txt”}
“TextEdit got an error: AppleEvent handler failed.”

Browser: Safari 530.19
Operating System: Mac OS X (10.5)

ok,

I found a solution. I’m sure there is a more efficient way to do this but i have not figured it out

tell application “Finder” to set the clipboard to name of (info for (filename as alias))

	tell application "TextEdit"
		activate
		
		save document "Untitled" in file {"Macintosh HD:Sima_data:processing_tests:" & (the clipboard) & ".txt"}
	end tell

cheers

Nic

Hi,

braces {} define a list, don’t use it instead of parentheses
This is sufficient


.
save front document in "Macintosh HD:Sima_data:processing_tests:" & filename & ".txt"
.

thanks Stefan!

(and for the pointer on using {} in the correct manner)