2016-05-08 46 views
0

我想用一個簡單的腳本/應用程序來運行任何鼠標左鍵單擊。 只要我點擊一個鏈接,就可以在網站上輸入數據。任何左鍵單擊運行applescript應用程序。鼠標監聽器或第三方擴展?

我看過不同的快捷方式擴展,我找不到任何工作。 我只是想將動作綁定到左鍵單擊。

我也搜索了能夠檢測到任何左鍵單擊然後運行腳本的其餘部分的applescript鼠標監聽器,但我找不到任何腳本。

腳本運行鼠標點擊的瞬間很重要。

+0

您可以輕鬆地能創建一些打開頁面(並更改它)的內容。你可以點擊AppleScript來運行它。 – Laurel

+0

這實際上很難。我必須點擊一個鏈接是隨機的產品,所以唯一的標識符是圖片本身。在鏈接標籤之間也有一個產品說明,但它們不包含產品的顏色,所以我仍然需要打開每個產品的6個,然後在每個產品上運行腳本以檢查顏色。總而言之,使用querySelectorAll()和innerHtml需要6秒。我想要的是一個腳本,它運行後立即點擊它,然後變爲可用 – LasseAarhus

+0

您試圖以非常無效的方式解決此問題。如果您使用scraping和applescript的組合,您可能能夠完成您想要的任務。如果我有頁面源的鏈接,我可以編寫一個正則表達式來查找圖片的鏈接。 – Laurel

回答

0

這是一個鼠標偵聽器,您可以在AppleScript腳本中運行。

set myAppleScriptPath to quoted form of "/Users/myUserName/Desktop/someScript.scpt" -- change it to the path of your appleScript 

set pyScript to quoted form of ("import os 
from AppKit import NSObject, NSApplication, NSEvent, NSLeftMouseUpMask 
from PyObjCTools import AppHelper 
class AppDelegate(NSObject): 
    def applicationDidFinishLaunching_(self, aNotification): 
     AppDelegate.myMonitor=NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSLeftMouseUpMask, self.leftMouseClick) 

    def applicationWillTerminate_(self, notification): 
      NSEvent.removeMonitor_(AppDelegate.myMonitor) 
      AppHelper.stopEventLoop() 

    def leftMouseClick(event): 
     os.system(\"osascript " & myAppleScriptPath & "\") 

tDeleg=AppDelegate.new() 
NSApplication.sharedApplication().setDelegate_(tDeleg) 
AppHelper.runEventLoop()") 

-- this run the NSLeftMouseUp listener, and this listener launch an Applescript 
do shell script "/usr/bin/python -c " & pyScript & "> /dev/null 2>&1 &" -- this launch the "Python" application , and quit this script 
-- to stop the listener, quit the "Python" application from the Dock 

此腳本啓動偵聽器。對於每次左鍵單擊(在鼠標上),偵聽器都會啓動第一行中指定的AppleScript

要停止監聽,如果你想在鼠標監聽下來只需要退出從碼頭

的「的Python」應用程序,腳本改變NSLeftMouseUpMaskNSLeftMouseDownMask

+0

謝謝!這完全有效。我必須在開始「點擊」​​之前啓動腳本,因爲python腳本必須啓動。除此之外,它的效果很好。非常感謝! – LasseAarhus