0

我一直在为 Alfred 2 编写一个工作流程,该工作流程在用户桌面上采用选定的 jpeg - 将其插入谷歌浏览器,然后使用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

但将其替换为shell脚本

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

使用系统事件错误停止工作流

现有的脚本(cl.ly 链接)

4

1 回答 1

0

You could put cliclick in the resource folder of your app and call it like this:

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

Or let curl do the job:

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 'encoded_image=@" & imagefile & ¬
    "' https://www.google.com/searchbyimage/upload | grep 'tbs=sbi' | sed 's/^.*http/http/;s/\".*$//')"

curl -F uploads the file to reverse search. The output is a redirect which includes the URL to the google result page.

于 2015-04-02T21:33:54.930 回答