努力在 applescript 工作流程中引用 cliclick(存储在与脚本相同的位置)
Struggling to reference cliclick (stored in the same location as script) within applescript workflow
我一直在为 Alfred 2 编写一个工作流程,它在用户桌面上获取一个选定的 jpeg - 将其插入 google chrome 然后使用 cliclick 右键单击并反转通过 google 搜索搜索图像。
我似乎无法避免让用户点击那里的主文件夹任何尝试在其他地方引用该文件似乎 return applescript 中的系统事件错误。
如有任何帮助,我们将不胜感激! (我对 applescript 非常陌生,如果这是一个非常简单的问题,alfred 深表歉意)
--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"
因系统事件错误停止工作流
您可以将 cliclick 放在您应用的资源文件夹中,并这样调用它:
set pathtocc to quoted form of (POSIX path of (path to resource "cliclick"))
do shell script pathtocc & " -h"
或者让 curl 来完成这项工作:
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 上传文件反向搜索。输出是一个重定向,其中包括 URL 到 google 结果页面。
我一直在为 Alfred 2 编写一个工作流程,它在用户桌面上获取一个选定的 jpeg - 将其插入 google chrome 然后使用 cliclick 右键单击并反转通过 google 搜索搜索图像。
我似乎无法避免让用户点击那里的主文件夹任何尝试在其他地方引用该文件似乎 return applescript 中的系统事件错误。
如有任何帮助,我们将不胜感激! (我对 applescript 非常陌生,如果这是一个非常简单的问题,alfred 深表歉意)
--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"
因系统事件错误停止工作流
您可以将 cliclick 放在您应用的资源文件夹中,并这样调用它:
set pathtocc to quoted form of (POSIX path of (path to resource "cliclick"))
do shell script pathtocc & " -h"
或者让 curl 来完成这项工作:
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 上传文件反向搜索。输出是一个重定向,其中包括 URL 到 google 结果页面。