Catalina update broke script

j_tanudjaja
New Contributor III

Hi All,

Hoping to get some help here.

One of the minor Catalina update broke my script. It was working until at least 10.15.1

I have an osascript running at login that is triggered by Launch Agents.
The script will display a dialog box.

The launch agent is definitely loaded. I can also see osascript running from Activity Monitor

launchctl list | grep acme 873 0 com.acme.WifiLoginPrompt

but the dialog box doesn't appear. If I unload and reload the plist then the dialog box will appear

launchctl unload ~/Library/LaunchAgents/com.acme.WifiLoginPrompt.plist launchctl load ~/Library/LaunchAgents/com.acme.WifiLoginPrompt.plist

Any suggestions?

Note: this only happens on the very first login attempt, subsequent login will be fine

Thanks for looking!

Launch agent plist below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <false/>
    <key>Label</key>
    <string>com.acme.WifiLoginPrompt</string>
    <key>LaunchOnlyOnce</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/Shared/.Script/WifiLoginPrompt.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Script is to prompt user for their password and create a keychain entry

#!/usr/bin/osascript

-- REVIEW ACTIONS ASK FOR USER CONFIRMATION
display dialog "Welcome to ACME
Please have your computer login password ready before proceeding to connect to the Wi-Fi." buttons {"OK"} default button "OK" --with icon caution

set t to "" -- all purpose variable holds various types of data
set label to "STAFF WIFI" --e        -- if omitted, service name is used as default label
set KeyKind to "802.1X Password" --e unless new type is "Internet password", then --n
set AcctName to do shell script "echo $LOGNAME"
set Acctpassword to text returned of (display dialog "Please enter your login password to connect to ACME Wi-Fi" default answer "" with hidden answer) -- n
set ServiceName to "com.apple.network.eap.user.item.wlan.ssid.STAFF WIFI" --n
set AcctComments to "Keychain Added via Apple Script." --e
set WifiPort to do shell script ("networksetup -listallhardwareports | awk '/Hardware Port: Wi-Fi/,/Ethernet/' | awk 'NR==2' | cut -d ' ' -f 2")


-- CONFIGURE WI-FI CONNECTION 
try
    set t to do shell script "security add-generic-password -a " & QAcctName & " -s " & QServiceName & " -w " & QAcctpassword & " -l " & Qlabel & " -j " & QAcctComments & " -D " & QKeyKind & " -T '/System/Library/SystemConfiguration/EAPOLController.bundle/Contents/Resources/eapolclient' -T '/usr/bin/security' -T '/System/Library/CoreServices/SystemUIServer.app' -T '/System/Applications/System Preferences.app' -T 'group://AirPort'" & " -A " & "-U"
end try


-- TURN OFF AIRPORT
do shell script "`networksetup -setairportpower " & QWifiPort & " off`"


try
    do shell script "`networksetup -setairportpower " & QWifiPort & " off `"
    do shell script "sleep 2"
    do shell script "`networksetup -setairportpower " & QWifiPort & " on `"
    do shell script "`networksetup -addpreferredwirelessnetworkatindex  " & QWifiPort & " " & Qlabel & " 0 WPA2E`"        
end try

display dialog "All Done! Welcome to the ACME Network" buttons {"OK"} default button "OK"

-- REMOVE LAUNCH AGENT
do shell script "rm -rf ~/Library/LaunchAgents/com.acme.WifiLoginPrompt.plist"
3 REPLIES 3

mm2270
Legendary Contributor II

It might help us help you if you post the script here, or at least the relevant part of it that is getting stuck.
But outside of that, does anything regarding PPPC need to be updated perhaps? What update did you notice broke this? Was it the most recent one?
Lastly, do you have any delay happening in your script before it attempts to display the dialog? I'm just wondering if it's firing too soon after login.

j_tanudjaja
New Contributor III

Thanks! updated with the code.

good idea, I will put delay in the beginning of the code and see what happens

mm2270
Legendary Contributor II

I wonder if this would be better as a bash or zsh script, and then just call osascript in it as needed for the dialogs. Because most of what you're doing in the script can be done easier in the shell than with straight AppleScript. Just a thought, and I have no idea if it has anything to do with why it stopped working. It's just an observation.

Do post back on your results after putting a slight delay in the script, or perhaps even detecting when the Dock/Finder is fully up and running before actually trying to show any dialogs. That might help.