I am working on a script that uses GUI Scripting to test for (and, if necessary) change the setting in the Keyboard preference pane “Use all F1, F2, etc. keys as standard function keys.” So my script includes a line like this one:
click checkbox ""Use all F1, F2, etc. keys as standard function keys."
Is there a way to write the script so that it will work correctly on French, German, Italian, and any other system? Or must I test the system system language and use a variable that contains each of the different strings for each language?
Thank you for any advice and help.
To answer my own question: the answer is to use numbered items, not the text of the items. For example, the following will reset the “Use F1, F2, etc.” checkbox to blank. I wrote this script so that it can be launched when I run the DOSBox DOS emulator software; the script that launches DOSBox tests whether the Fn keys are used as standard Fn keys, and, if they are not so used, it checks that “Use F1, F2” box. This script will in the background while DOSBox is running, and reset the checkbox when it closes.
on run
set dosRunning to true
repeat until dosRunning = false
tell application "System Events"
set dosRunning to (application process "DOSBox" exists)
delay 1
end tell
end repeat
set prefsRunning to false
tell application "System Events"
if (name of processes) contains "System Preferences" then
set prefsRunning to true
end if
end tell
tell application "System Preferences"
if prefsRunning is true then
set currentPane to current pane
set flag to true
try
currentPane -- errors if current pane is empty
on error
set flag to false
end try
end if
reveal anchor 1 of pane id "com.apple.preference.keyboard" -- anchor 1 is anchor "KeyboardTab"
end tell
tell application "System Events"
if UI elements enabled then
tell application process "System Preferences"
-- checkbox 1 below is checkbox "Use all F1, F2, etc. keys as standard function keys"
-- window 1 below is window "Keyboard"
if value of checkbox 1 of tab group 1 of window 1 is 1 then
click checkbox 1 of tab group 1 of window 1
end if
end tell
tell application "System Preferences"
if prefsRunning is false then
quit
else
if flag then
set current pane to currentPane
else
set show all to true
end if
end if
end tell
else
-- GUI scripting not enabled.
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
display dialog "GUI scripting must be enabled for me to reset your keyboard preferences." & return & return & "Please check the box next to \"Enable access for assistive devices\". " buttons {"OK"}
end tell
end if
end tell
end run
I realize this is probably very inefficient, but it seems to work, thanks to the help of many posts on this forum!