Having recently needed to convert a large pile of .ods and .xlsx to .xls for uniformity, I created the following AppleScript. To make it, I tried using Automator to record actions, but couldn't edit the list of actions recorded to make it generic, rather than specific to the document that was on top.
However, I found that if you select a number of recorded actions from inside the 'recorded actions' box in Automator and drag them into the empty space below the command, it will generate an AppleScript of those actions.
I was also having problems with the action timing out during the switch and open save dialog. I fixed this by deleting the on error event, so that the command would continue to try until the timeout elapsed. That seemed to work.
Here's the script:
on run {}
-- Click "NeoOffice" in the Dock.
set timeoutSeconds to 0.3
set uiScript to "click UI Element \"NeoOffice\" of list 1 of application process \"Dock\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Press ⇧⌘S
delay 0.2
set timeoutSeconds to 1
set uiScript to "keystroke \"s\" using {shift down, command down}"
my doWithTimeout(uiScript, timeoutSeconds)
-- Make a selection from the popupbutton.
delay 0.2
set timeoutSeconds to 1
set uiScript to "click pop up button 1 of group 1 of window \"Save\" of application process \"NeoOffice\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Microsoft Excel 97/2000/XP (.xls)
delay 0.2
set timeoutSeconds to 0.2
set uiScript to "click menu item \"Microsoft Excel 97/2000/XP (.xls)\" of menu 1 of pop up button 1 of group 1 of window \"Save\" of application process \"NeoOffice\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the "Save" button.
delay 0.2
set timeoutSeconds to 0.2
set uiScript to "click UI Element \"Save\" of window \"Save\" of application process \"NeoOffice\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Press ⌘W
delay 0.2
set timeoutSeconds to 0.2
set uiScript to "keystroke \"w\" using command down"
my doWithTimeout(uiScript, timeoutSeconds)
end run
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
end if
end try
end repeat
end doWithTimeout
Mac OS X Hints
http://hints.macworld.com/article.php?story=20110404090331584