0

非常に便利な AppleScript を他の Mac 管理者と共有したかったのですが、焦点が合っていません。AppleScript エディターで実行すると、特定の段階まで実行され、必要なウィンドウにテキストをコピーする代わりに、AppleScript エディターでテキストを置き換えます。誰でも理由を提案できますか?

set vpnname to "VPN (Primary)"
set vpnserver to "vpn.website.com"
set vpnsecret to "abcdefghij"
set vpnusername to system attribute "USER"
set groupname to "GROUP"

activate application "System Preferences"
tell application "System Events"

    -- Checks whether Universal Access is enabled - this is required for all scripts to work
    if not (UI elements enabled) then
        tell application "System Preferences"
            activate
            set current pane to pane id "com.apple.preference.universalaccess"
            display dialog "This script requires access for assistive devices be enabled." & return & return & "To continue, click the OK button and enter an administrative password in the security dialog." with icon note
        end tell
        set UI elements enabled to true
        if UI elements enabled is false then return "User Cancelled"
        delay 1
    end if

    tell process "System Preferences"
        click button "Network" of scroll area 1 of window "System Preferences"

        --Creating VPN (CU Primary) interface
        tell window "Network"
            click button "Add Service"
            delay 1
        end tell

        tell sheet 1 of window "Network"

            click pop up button 1
            click menu item "VPN" of menu 1 of pop up button 1
            delay 1
            click pop up button 2
            click menu item "Cisco IPSec" of menu 1 of pop up button 2
            set focused of text field 1 to true
            keystroke "a" using command down
            keystroke vpnname
            click button "Create"
            delay 1
        end tell

        --Entering server / account details
        tell group 1 of window "Network"
            click checkbox "Show VPN status in menu bar"
            set focused of text field 3 to true
            keystroke vpnserver
            set focused of text field 1 to true
            keystroke vpnusername
            click button 2 --pressing "Advanced…" button
            delay 1
        end tell

        --Entering "Advanced…" details
        tell sheet 1 of window "Network"
            activate
            set focused of text field 2 to true
            keystroke vpnsecret
            set focused of text field 1 to true
            keystroke groupname
            click button "OK"
            delay 1
        end tell

        -- Apply all changes
        tell window "Network"
            click button "Apply"
            delay 1
        end tell

        tell application "System Preferences"
            quit saving yes
        end tell

    end tell
end tell
4

1 に答える 1