0

我想与其他 Mac 管理员分享一个非常有用的 AppleScript,但它正在失去焦点。当它在 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

0

我不确定它是否会起作用,但如果有任何击键进入applescript,只需运行

告诉应用程序“此处的应用程序名称”
激活
结束告诉

在输入苹果脚本的击键之前,它将专注于您告诉它的窗口

抱歉缺少代码片段我是这个论坛的新手,我不知道如何正确使用它

于 2014-01-30T10:15:21.800 回答