I want to open a csv file with OpenOffice, but not with the default encoding (I need “Europe occidentale (ISO-8859-1)” and not “Unicode (UTF-8)”).
With the script I wrote, I get no error message ; the window of OpenOffice opens but there is no change in the pop up button “Jeu de caractères”.
Thanks for your help,
Nicolas
set TheApplication to “imac:Applications:OpenOffice.org.app” as alias
set theFile to (path to desktop) & “Calendri.csv” as string
alias theFile
tell application “Finder” to open file theFile using application file TheApplication
tell application “OpenOffice.org” to activate
tell application “System Events”
tell application process “OpenOffice.org”
repeat until window 1 exists
end repeat
tell window 1
tell pop up button “Jeu de caractères”
click
end tell
delay 2
click menu item “Europe occidentale (ISO-8859-1)” of menu of pop up button “Jeu de caractères”
click button “OK”
end tell
end tell
end tell
Model: iMac
AppleScript: 2.0.1
Browser: Firefox 3.5.3
Operating System: Mac OS X (10.5)
I have always found using GUI scripting for pop-up buttons awful. It involves plenty of trial and error.
I would suggest you one modification:
instead of using
tell pop up button "Jeu de caractères"
click
end tell
delay 2
click menu item "Europe occidentale (ISO-8859-1)" of menu of pop up button "Jeu de caractères"
you have to use something like this:
tell pop up button "Jeu de caractères"
click
delay 2
click menu item "Europe occidentale (ISO-8859-1)" of menu 1 --i cannot be sure about the menu number, you have to find it out
end tell
or you can try something like this:
tell pop up button "Jeu de caractères"
click
delay 1
keystroke "eu"
delay 1
keystroke return
end tell
1- When I use the keystroke, it works, but with an item “Europe de l’est” which is not the item I would like. If I use keystroke “europe occidentale” it selects an item “Latin”. Is there a possibility to select the right item using keystroke ?
2- When I use the menu item of menu 1, I get an error message. I downloaded the trial version of Prefab’s UI browser, and the pop up button’s child is a “text entry area” (text area 1 of pop up button 1).
I tried :
set value of text area 1 of pop up button 1 to "Europe occidentale (ISO-8859-1)"
. No error message but no action.
When I try :
display dialog (the value of text area 1 of pop up button 1) as string
, I obtain “Unicode (UTF-8)” which is the default value I want to avoid.
That’s what i said earlier, you have to do trial and error to get it right. I am not using OpenOffice, so I can’t tell you exactly what you should use. I can give you a tip though
you can use down arrow or up arrow to reach to “europe occidentale” from “Europe de l’est”
key code 125 --down arrow key
key code 126 --up arrow key
Instead of using 17 down keystrokes, you may want to reach closer to the desired item and then send fewer down keystrokes
or go down and send fewer up keystrokes.
Secondly, when you do GUI scripting always avoid using names like
tell pop up button “Jeu de caractères”
instead use
tell pop up button 1 --or whatever number
so that the script works for those whose default system language is not the same as yours.
Thanks for the advice, I could go as low as a loop of 4
Regarding the naming of the buttons, I understand your point ; nevertheless, it is disappointing, because understanding the script (when reading it after a while) is much easier when you read button “something” than button 1.