简体   繁体   中英

How to get dialog box focus in AppleScript in Mac OS 10.10 Yosemite

I wrote a simple script to have an Active Directory user install a specific keychain required for network access. I've used it successfully on 10.7-10.9 and the instruction prompts came up fine.

When 10.10 came around, the "activate" command didn't bring the program to the front anymore. Instead, after Keychain Access came up, the AppleScript icon would just bounce like crazy on the dock.

Here's the code:

activate
display dialog "Welcome to the Mac Network Cerificate Installer (Version 6.0)" & return & return & "Click Okay to start installation of the Mac Network Certificate. Please wait until the next dialog box shows up." with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Bonjour.icns" buttons {"Okay"} default button 1 with title "WONK"

delay 2

activate application "Keychain Access"

tell application "Finder" to open POSIX file "/Files/bn-virtualcar.crt"

delay 2

activate
display dialog "In the Keychain Access prompts, click the 'Add' then 'Always Trust'." & return & return & "After you have entered your password, close Keychain Access by clicking 'Keychain Access' in the top left corner and selecting Quit." with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Bonjour.icns" buttons {"Okay"} default button 1 with title "WONK"

delay 2

tell application "System Events" to delete login item "Mac-Network-Cert"

There's a similar question at How to ensure Applescript dialog focus in OS X 10.10 (Yosemite)? , but it doesn't work for me since these aren't password prompts or shell scripts. I just want two instructions boxes to show up.

Any help would be appreciated.

Your dialogs should look like this, to ensure focus, or stick them into the Finder tell block.

tell application "SystemUIServer"
    activate
    display dialog "Welcome to the Mac Network Cerificate Installer (Version 6.0)" & return & return & "Click Okay to start installation of the Mac Network Certificate. Please wait until the next dialog box shows up." with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Bonjour.icns" buttons {"Okay"} default button 1 with title "WONK"
end tell

delay 2

activate application "Keychain Access"

tell application "Finder" to open POSIX file "/Files/bn-virtualcar.crt"

delay 2
tell application "SystemUIServer"

    activate
    display dialog "In the Keychain Access prompts, click the 'Add' then 'Always Trust'." & return & return & "After you have entered your password, close Keychain Access by clicking 'Keychain Access' in the top left corner and selecting Quit." with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:Bonjour.icns" buttons {"Okay"} default button 1 with title "WONK"
end tell
delay 2

tell application "System Events" to delete login item "Mac-Network-Cert"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM