• Warum funktioniert dieses AppleScript nicht?

    Vorweg:
    Ich habe es von ChatGPT erstellen lassen (ja, ich weiß ...), weil ich das selbst nicht kann. Es soll einen Arbeitsschritt im Computerservice vereinfachen.
    Die Anforderung ist so definiert:

    There is a folder on the desktop named "VMEDaction". Inside is a certificate named "Proxy2.cer". This certicivate needs to be added to keychain.app. Also the URL "http://vmed.test.wap" needs to be added in network settings as path to a proxy server.

    Das Ergebnis war:
    Show Plain Text
    1. -- Add certificate to Keychain.app and set it as trusted
    2. tell application "Keychain Access"
    3.     set certificatePath to POSIX path of (path to desktop folder) & "VMEDaction/Proxy2.cer"
    4.     set newCert to (contents of certificatePath)
    5.     set certRef to add newCert with password "" to keychain "login.keychain"
    6.     set trust settings of certRef to {always trust}
    7. end tell
    8.  
    9. -- Add URL as a proxy server in network settings
    10. tell application "System Preferences"
    11.     activate
    12.     reveal pane id "com.apple.preference.network"
    13. end tell
    14.  
    15. tell application "System Events"
    16.     tell process "System Preferences"
    17.         delay 1 -- Wait for the pane to be revealed (adjust delay if needed)
    18.         click button "Proxies" of window "Network"
    19.         delay 1 -- Wait for the Proxies tab to load (adjust delay if needed)
    20.  
    21.         -- Enable Web Proxy (if not already enabled)
    22.         if value of checkbox "Web Proxy (HTTP)" of tab group 1 of group 1 of window "Network" is 0 then
    23.             click checkbox "Web Proxy (HTTP)" of tab group 1 of group 1 of window "Network"
    24.         end if
    25.  
    26.         -- Add the URL as a proxy server
    27.         set value of text field "Web Proxy Server" of tab group 1 of group 1 of window "Network" to "http://vmed.test.wap"
    28.  
    29.         click button "Apply" of window "Network"
    30.     end tell
    31. end tell

    Als Ergebnis kommt aber:
    Syntax error: Zeilenende, etc. erwartet, aber Identifier gefunden.
    Ist das so schlecht programmiert, oder was spricht gegen den Code?

    Falls da jemand eine Idee hat, wäre ich äußerst dankbar.
    • Das script funktioniert nicht, weil Keychain Access.app kein AppleScript Dictionary mehr hat…

      Apple hat das schon vor ein paar Jahren entfernt, somit ist es mit AppleScript nicht mehr ansprechbar.

      Und in Ventura funktioniert das GUI scripting von System Preferences auch nicht mehr in dieser Art, weil die App jetzt System Settings heisst und die UI Elemente ganz anders angeordnet sind.
      ----------
      Gruss

      Stefan
    • PS: Für das setzen des Web Proxies gibt es eine Alternative…

      Show Plain Text
      1. do shell script "networksetup -setwebproxy Ethernet http://vmed.test.wap 80"

      Falls nicht die Ethernet-Schnittstelle benutzt wird, musst du Ethernet durch die andere Schnittstelle ersetzen.

      Die Namen der verfügbaren Schnittstellen kannst du dir Im Terminal mit

      Show Plain Text
      1. networksetup -listallnetworkservices

      anzeigen lassen.
      ----------
      Gruss

      Stefan