2013-07-03 42 views
1

Ok Unity3d允许您在应用程序首选项中设置外部脚本编辑器。所以我想用applescript来启动我自己的编辑器。目前为止,这个applescript对我来说工作得非常好,但我一直无法跳到行号。在AppleScript中捕获AppleEvent

根据统一的“行数应该通过在一个的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 

回答

0

如果处理开放时,你应该会看到一些参数,包括行号:

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