Hi,
I’ve been haunting this forum for some weeks, but never posted before because I’ve always managed to find what I wanted amongst previous posts - so can I begin by thanking all the gurus here for sharing your knowledge so generously.
I’m trying to write a script that will convert rtf files to html with TextEdit. I know there are dozens of posts already about this, but I still can’t get exactly what I want.
This script, using textutil works perfectly:
set ASTID to AppleScript's text item delimiters
choose file with multiple selections allowed without invisibles
repeat with thisFile in result
try
set thisFile to POSIX path of thisFile
do shell script "/usr/bin/textutil -convert html " & quoted form of result
set AppleScript's text item delimiters to {"."}
set thisFile to text items 1 through -2 of thisFile
set AppleScript's text item delimiters to {""}
set thisFile to thisFile as text
end try
end repeat
set AppleScript's text item delimiters to ASTID
But using it I’ve discovered that textutil writes a slightly less clean form of html than TextEdit. Basically, TextEdit preferences allows me to set html saving options as I want them - ie XHTML 1.0 Strict, No CSS and Unicode (UTF-8).
So my first question is: Is it possible to access preferences for textutil ?
My next attempt was using GUI scripting:
tell application "TextEdit"
set new_file to (choose file with prompt "Open file to be edited:")
open new_file
end tell
tell application "System Events"
tell process "TextEdit"
keystroke "S" using command down -- shift-command-S
delay 1
key code 55
tell pop up button 1 of group 1 of sheet 1 of window 1 -- file type selector
click
delay 1
key code 125 -- down arrow
delay 1
key code 125 -- down arrow
delay 1
key code 36 -- select from menu
delay 1
key code 48
key code 48
delay 1
end tell
end tell
end tell
It worked at first, and then suddenly stopped working with the following error message:
click pop up button 1 of group 1 of sheet 1 of window 1 of process "TextEdit"
"System Events got an error: Can't get pop up button 1 of group 1 of sheet 1 of window 1 of process \"TextEdit\". Invalid index."
Any comments would be much appreciated. Many thanks in advance.
Mike