2013-07-03 39 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