在Applescript中捕获AppleEvent

时间:2013-07-03 01:53:50

标签: macos applescript unity3d

Ok Unity3d允许您在应用程序首选项中设置外部脚本编辑器。所以我想使用applescript来启动我自己的编辑器。到目前为止,这个苹果对我来说效果很好,但是我无法跳到行号。

根据Unity的说法,“行号应该通过AppleEvent中的参数发送。它应该是typeChar和keyAEPosition('kpos')。通过此参数发送的结构具有以下布局:”

struct TheSelectionRange 
{
    short unused1; // 0 (not used)
    short lineNum; // line to select (<0 to specify range)
    long startRange; // start of selection range (if line < 0)
    long endRange; // end of selection range (if line < 0)
    long unused2; // 0 (not used)
    long theDate; // modification date/time
};

“lineNum应填充正确的行。其他字段不会填充0和-1以外的任何字段。”

那么为什么我看不到任何这些通过我的输入?我如何捕获这个苹果事件?

我的剧本:

on run input
    set element to item 1 of input
    if (element is in {{}, {""}, ""}) then
        return
    else
        tell application "System Events"
            set ProcessList to name of every process
            if "iTerm" is in ProcessList then
                set iterm_running to true
            else
                set iterm_running to false
            end if
            log iterm_running
        end tell
        tell application "iTerm"
            activate
            if (count terminal) < 1 then
                set term to (make new terminal)
            else
                set term to current terminal
            end if
            tell term
                set create_session to false
                try
                    do shell script ("/usr/local/bin/vim --servername UNITY --remote-send ''")
                    set create_session to false
                on error errorMessage number errorNumber
                    set create_session to true
                end try

                if iterm_running then
                    if create_session then
                        launch session "Default Session"
                        activate current session
                        tell current session
                            set name to "Unity"
                            write text "/usr/local/bin/vim --servername UNITY --remote-silent \"$(echo \"/Volumes/" & input & "\" | tr : /)\""
                        end tell
                    else
                        do shell script ("/usr/local/bin/vim --servername UNITY --remote-silent \"$(echo \"/Volumes/" & input & "\" | tr : /)\"")
                    end if
                else
                    activate current session
                    tell current session
                        set name to "Unity"
                        write text "/usr/local/bin/vim --servername UNITY --remote-silent \"$(echo \"/Volumes/" & input & "\" | tr : /)\""
                    end tell
                end if
            end tell
        end tell
    end if
    return input
end run

1 个答案:

答案 0 :(得分:0)

如果你处理open事件,你应该看到一些参数,包括行号:

on open (x,y)
  display dialog x
  display dialog y
  -- use x and y in your own script
end open