2015-04-02 15 views
0

我一直在爲用戶桌面上的選定jpeg編寫Alfred 2的工作流程 - 將其插入到Google Chrome中,然後使用cliclick右鍵單擊並通過谷歌搜索反向搜索圖片。努力在applescript工作流程中引用cliclick(存儲在與腳本相同的位置)

我似乎無法避免讓用戶將cliclick放在主文件夾中任何嘗試引用其他地方的文件似乎都會在applescript中返回系統事件錯誤。

任何幫助,將不勝感激! (我非常新的AppleScript和阿爾弗雷德道歉,如果這是一個很簡單的問題)

--get location of selected folder 
tell application "Finder" 
    set sel to the selection as text 
    set the clipboard to POSIX path of sel 
end tell 

activate application "Google Chrome" 
--open selected jpeg in google chrome 
tell application "System Events" to tell process "Google Chrome" 
    delay 1 
    keystroke "t" using command down 
    keystroke "v" using command down 
    key code 36 
    delay 1 
    -- calculate the top left corner of the image 
    set myBounds to bounds of window 1 of application "Google Chrome" 
    set x to item 1 of myBounds 
    set y to item 2 of myBounds 
    --locate cliclick in users home 
    set uHome to get path to home folder 
    set locHome to POSIX path of uHome 
    --run the right click -> search by image mouse event 
    do shell script "" & locHome & "/cliclick m:" & x & "," & y & "w:100 kd:ctrl c:+2,+74 ku:ctrl w:1000 c:+66,+90 w:700" 
end tell 

--close "file://" tab 
tell application "Google Chrome" 
    set windowList to every tab of every window whose URL starts with "file://" 
    repeat with tabList in windowList 
     set tabList to tabList as any 
     repeat with tabItr in tabList 
      set tabItr to tabItr as any 
      delete tabItr 
     end repeat 
    end repeat 
end tell 

我嘗試使用

set UnixPath to POSIX path of ((path to me as text) & "::" & "cliclick") 

在更換

set uHome to get path to home folder 
set locHome to POSIXpath of uHome 

,但在更換到外殼腳本與

do shell script "" & UnixHome & " m:" & x & "," & y & "w:100 kd:ctrl c:+2,+74 ku:ctrl w:1000 c:+66,+90 w:700" 

停止工作流程與系統事件錯誤

The Script as it stands (cl.ly link)

回答

0

你可以把cliclick在您的應用程序的資源文件夾,並調用它像這樣:

set pathtocc to quoted form of (POSIX path of (path to resource "cliclick")) 
do shell script pathtocc & " -h" 

還是讓嫋嫋做的工作:

set imagefile to POSIX path of ¬ 
    (choose file of type "public.image" default location path to desktop) 

do shell script " 
open -a 'Google Chrome' $(curl -F '[email protected]" & imagefile & ¬ 
    "' https://www.google.com/searchbyimage/upload | grep 'tbs=sbi' | sed 's/^.*http/http/;s/\".*$//')" 

curl -F上傳文件進行反向搜索。輸出是一個重定向,其中包含谷歌結果頁面的URL。

+0

仍嘗試調用cliclick資源文件夾使用您的代碼也錯誤,但捲曲腳本工作1000倍更好,已完全吹拂我的心xD 謝謝! – Jeremy 2015-04-02 22:36:58

+0

對捲曲不太瞭解 - 發送腳本後是否存在延遲的特殊原因?它的平均時間約爲13秒,感覺很奇怪:3是否因爲我通過applescript調用curl? – Jeremy 2015-04-02 23:02:20

+0

需要時間上傳圖片。 – user309603 2015-04-03 00:35:41