This should be real simple but I just can’t seem to get it to work.
I need to open an XML document in TextEdit and copy the contents into FileMaker.
I was able to set a field in FileMaker to the contents of the XML document but that gave me a space after every character.
Opening & closing the file isn’t a problem but how do I tell TextEdit to copy the entire document to the clipboard?
Actually, you don’t even need TextEdit for this:
set a to choose file
set b to open for access a
set c to read b
close access b
set the clipboard to c
Just read the file into a variable, and set the clipboard to that variable. You can now paste the data anywhere you want.
Depending on the file’s encoding, you may need adding an extra “as «class utf8»” to the “read” statement.
If I try the script without the “as «class utf8»” I get an invisible character after each real character.
When I run the script
set a to choose file
set b to open for access a
set c to read b as «class utf8»
close access b
set the clipboard to c
the section “read b as «class utf8»” is highlighted and the error
“Can’t make some data into the expected type.” is returned.
I assume I have the wrong encoding, how do I find out the correct encoding?
Which version of OS X are you working with? It works on my machine, which is running 10.4.6.
You could also use GUI Scripting. I don’t have filemaker, but this works when I choose a different application. You may need to increase the delay time if you want the script to launch FileMaker, rather than manually launching it before running the script.
tell application "TextEdit" to activate
tell application "System Events" to keystroke "ac" using command down
tell application "FileMaker" to activate
delay 0.1
tell application "System Events" to keystroke "v" using command down
This should mean it’s a UTF-16 file. So, try replacing “«class utf8»” with “Unicode text” and it may work fine now.
If it’s a UTF-16 file, first two bytes should be 0xFEFF if big-endian (mac) or 0xFFFE if little-endian (win). Ie:
try
if (read (alias "julifos:Users:julifos:Desktop:tst:asdf.txt") for 2) is in {(ascii character 255 & ascii character 254),(ascii character 254 & ascii character 255)} then display dialog "Seems Unicode text (UTF-16)!" with icon note
end
I’m running 10.3.9
The solution provided by Torajima is exactly what I’m looking for.
Thanks again guys!