2013-09-24 37 views
0

我想捕獲在Safari與蘋果腳本中的鼠標點擊事件。我的Applescript完成它需要做的事情,但是如果用戶點擊Safari中的文檔,我想終止。我想在Applescript中設置一個On_Click事件,如果用戶點擊Safari文檔就會觸發該事件。陷阱鼠標點擊Safari瀏覽器與蘋果腳本

回答

0

我不知道如何用applescript「陷阱」鼠標事件。你必須使用objective-c和可可API。

但是,您可能會以另一種方式做到這一點。這是一個簡單的例子。將其保存爲待開啓的applescript應用程序。當你運行它時,Safari窗口將滾動。要暫停滾動,只需點擊applescript的停靠欄圖標即可。如果再次單擊停靠欄圖標,則滾動將再次開始,反之亦然。您會注意到,每次單擊停靠欄圖標時,都會執行「on reopen」處理程序,該處理程序會在true和false之間切換shouldScroll變量。

無論如何,我希望這給你一個想法讓自己的腳本工作。請記住,您可以通過右鍵單擊其停靠欄圖標並選擇退出來退出停留時間的applescript。祝你好運。

property shouldScroll : missing value 
property theCounter : missing value 
property counterMaxValue : missing value 

on run 
    tell application "Safari" to activate 
    set shouldScroll to true 
    set theCounter to 0 
    set counterMaxValue to 2000 
end run 

on reopen 
    tell application "Safari" to activate 
    set shouldScroll to not shouldScroll 
end reopen 

on idle 
    if shouldScroll then 
     if theCounter is greater than counterMaxValue then set theCounter to 0 
     tell application "Safari" to tell document 1 
      do JavaScript "window.scroll (0," & (theCounter as text) & ")" 
     end tell 
     set theCounter to theCounter + 20 
    end if 
    return 0.1 
end idle 
+0

謝謝。我試着運行腳本,但它沒有滾動我的Safari窗口。也許因爲我不知道你的意思是「保存爲開放式應用程序」。還有什麼是「碼頭圖標」?謝謝! –

+0

有人還建議我看看來自PFiddlesoft的UI操作。我已經下載了它,但還沒有嘗試過。 –

+0

將代碼複製/粘貼到AppleScript編輯器中。保存。在保存窗口的底部,將文件格式設置爲應用程序,並選中「在運行處理程序之後保持打開狀態」框。如果您雙擊保存的應用程序,它將在運行時像其他正在運行的應用程序一樣顯示在OSX Dock中,並且它將保持打開狀態,直到您退出爲止。試試看。 – regulus6633

0

當焦點窗口變成一個正常的瀏覽器窗口,例如通過測試,如果最前面的窗口有一個全屏按鈕,您可能會退出腳本:

tell application "System Events" to tell process "Safari" 
    repeat until exists value of attribute "AXFullScreenButton" of window 1 
     --do something 
     delay 1 
    end repeat 
end tell 

或者如果腳本應該停止時,Safari瀏覽器成爲最前面的應用程序:

repeat until frontmost of application "Safari" 
    --do something 
    delay 1 
end repeat 
+0

Safari窗口始終位於最前面。我有一個緩慢滾動Safari窗口的Applescript。我想在點擊窗口時暫停滾動。但我無法弄清楚如何捕捉點擊事件。 –