2013-07-10 29 views

回答

0

您可以使用下面的腳本訪問上下文菜單,您需要通過Google找到MouseLocation和cliclick。

您可能需要對其進行編輯(並將硬編碼路徑調整爲MouseLocation和cliclick),但它確實沒有問題,我認爲您可以使用System Events和關鍵代碼命令來導航上下文菜單。

set mouseLoc to (do shell script "/usr/local/opt/MouseLocation") 
set {astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","} 
tell mouseLoc to set {mouseX, mouseY} to {it's text item 1, it's text item 2} 
set {mouseX, mouseY} to {(mouseX as integer), 1200 - (mouseY as integer)} 

tell application "System Events" 
    set frontProcessName to name of every process whose frontmost is true 
    -- tell a to set aa to (get its name) 
    set wnCount to count of windows of process named frontProcessName 
    if wnCount > 0 then 
     tell window 1 of process named frontProcessName 
      set wnPos to its position 
      set wnsize to its size 
     end tell 
     set {wnX, wnY, wnWidth, wnHeight} to {item 1 of wnPos, item 2 of wnPos, item 1 of wnsize, item 2 of wnsize} 

     set {leftBound, RightBound, upperBound, lowerBound} to {wnX + 1, (wnX + wnWidth - 21), wnY + 50, (wnY + wnHeight - 51)} 
     if mouseX ≥ leftBound and mouseX ≤ RightBound then 
     else if mouseX < leftBound then 
      set mouseX to leftBound 
      log "a" 
     else 
      set mouseX to RightBound 
      log "b" 
     end if 

     if mouseY ≥ upperBound and mouseY ≤ lowerBound then 
     else if mouseY < upperBound then 
      set mouseY to upperBound 
      log "c" 
     else 
      set mouseY to lowerBound 
      log "d" 
     end if 

    end if 
end tell 
set mouseLoc to "c" & mouseX & " " & mouseY 
do shell script "/usr/local/opt/cliclick " & mouseLoc 
set AppleScript's text item delimiters to astid 

編輯:

我不知道,你無法通過谷歌找到MouseLocation了,我對此感到遺憾 如果編譯在這個線程在崗#3中發現的代碼問題(http://www.macscripter.net/viewtopic.php?id=33468),那麼我建議你使用MouseTool在這裏找到:(http://www.hamsoftengineering.com/codeSharing/MouseTools/MouseTools.html)代替,那麼您需要需要腳本的前四行更改爲類似:

set mouseLoc to (do shell script "MouseTools -location") 
set {astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return} 
tell mouseLoc to set {mouseX, mouseY} to {it's text item 1, it's text item 2} 
set {mouseX, mouseY} to {(mouseX as integer),(mouseY as integer)} 

(你必須調整到M的路徑ouseTools以及cliclick)

+0

嘿謝謝回答;你能鏈接到MouseLocation工具嗎?我已經嘗試過各種谷歌搜索,例如MouseLocation shell腳本,但Google沒有返回任何有用的內容 – SparrwHawk

+0

Hello。我很抱歉沒有找到谷歌MouseLocation。我在我的文章中提供了一個更好的替代工具。 HTH – McUsr

+0

嗨McUser,謝謝你的幫助。我收到此錯誤:無法將「MouseTools」轉換爲整型。我會在這裏粘貼我的代碼,但這太長了;但我已遵循你的指示。 – SparrwHawk

0

根據this post,似乎可以在系統內使用Universal Access進行此操作。

相關問題