UI scripting ...

Hi,

I wrote a little handler to unlock a system preference pane. When running, the preference pane moves to the frontmost level in the Finder and disturbs the user while in another app. Is it possible to have all UI scripting executed in background ? Here is my script:

on UnlockPowerManager()
   tell application "System Preferences"
       launch
       reveal anchor "Options" of pane id "uk.co.dssw.powermanager.preferencepane"
   end tell
   tell application "System Events"
       tell process "System Preferences"
           repeat until exists window "Power Manager"
               delay 0.5
           end repeat
           if exists (button [i]"Pour modifier, cliquez sur le cadenas." of group 2 of window "Power Manager"[/i]) then
               click button [i]"Pour modifier, cliquez sur le cadenas." of group 2 of window "Power Manager"[/i]
               delay 0.5
               tell application "System Events"
                   tell process "SecurityAgent"
                       set value of text field 1 of group 1 of window 1 to adminName
                       set value of text field 2 of group 1 of window 1 to adminPassword
                       delay 0.5
                       click button "OK" of group 2 of window "Authentification"
                   end tell
               end tell
           end if
       end tell
   end tell
end UnlockPowerManager

Thanks in advance.

Robert Lespérance

No, almost all UI actions work only if the targeted application is in the foreground

Hi StefanK,

You are always everywhere in this forum ? Your help is precious !

Regards.

Robert

I think StefanK is an AppleScript Knowledgebase Botâ„¢ designed by either Apple or MacScripter. Artifical Intelligence is here my friends… :lol:

All kidding aside, I’m always amazed at his “everywhereness” and thorough answers, not to mention patience.

To add to the discussion:

Scripts involing UI scripting can be very touchy. If you even touch the computer while it’s running, try to do anything else, UI scripts will generally fail and also run-amok, trying to execute UI instructions on whatever you have in the foreground. I’ve seen some wierd stuff violating this myself. :rolleyes: