ghostof101
ghostof101

Reputation: 187

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.

Upvotes: 0

Views: 2537

Answers (1)

McUsr
McUsr

Reputation: 1409

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"

Upvotes: 2

Related Questions