Shell 是否可以使用AppleScript访问右键单击上下文?
我想使用AppleScript之类的东西为键盘快捷键指定一个右键单击上下文 例如:Shell 是否可以使用AppleScript访问右键单击上下文?,shell,scripting,applescript,keyboard-shortcuts,dropbox,Shell,Scripting,Applescript,Keyboard Shortcuts,Dropbox,我想使用AppleScript之类的东西为键盘快捷键指定一个右键单击上下文 例如: 如果我右键单击Dropbox中的文件夹,它会给我一个共享Dropbox链接菜单。不使用鼠标就可以访问此内容吗?您可以使用下面的脚本访问上下文菜单,您需要鼠标定位和通过Google找到的cliclick 您可能需要对其进行一些编辑,并将硬编码路径调整为鼠标定位和cliclick,但这应该不会有问题,我认为您可以使用系统事件和键代码命令来导航上下文菜单 set mouseLoc to (do shell script
如果我右键单击Dropbox中的文件夹,它会给我一个共享Dropbox链接菜单。不使用鼠标就可以访问此内容吗?您可以使用下面的脚本访问上下文菜单,您需要鼠标定位和通过Google找到的cliclick 您可能需要对其进行一些编辑,并将硬编码路径调整为鼠标定位和cliclick,但这应该不会有问题,我认为您可以使用系统事件和键代码命令来导航上下文菜单
set mouseLoc to (do shell script "/usr/local/opt/MouseLocation")
set {astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ","}
tell mouseLoc to set {mouseX, mouseY} to {it's text item 1, it's text item 2}
set {mouseX, mouseY} to {(mouseX as integer), 1200 - (mouseY as integer)}
tell application "System Events"
set frontProcessName to name of every process whose frontmost is true
-- tell a to set aa to (get its name)
set wnCount to count of windows of process named frontProcessName
if wnCount > 0 then
tell window 1 of process named frontProcessName
set wnPos to its position
set wnsize to its size
end tell
set {wnX, wnY, wnWidth, wnHeight} to {item 1 of wnPos, item 2 of wnPos, item 1 of wnsize, item 2 of wnsize}
set {leftBound, RightBound, upperBound, lowerBound} to {wnX + 1, (wnX + wnWidth - 21), wnY + 50, (wnY + wnHeight - 51)}
if mouseX ≥ leftBound and mouseX ≤ RightBound then
else if mouseX < leftBound then
set mouseX to leftBound
log "a"
else
set mouseX to RightBound
log "b"
end if
if mouseY ≥ upperBound and mouseY ≤ lowerBound then
else if mouseY < upperBound then
set mouseY to upperBound
log "c"
else
set mouseY to lowerBound
log "d"
end if
end if
end tell
set mouseLoc to "c" & mouseX & " " & mouseY
do shell script "/usr/local/opt/cliclick " & mouseLoc
set AppleScript's text item delimiters to astid
您必须调整鼠标工具的路径以及cliclick的路径。根据,似乎可以在系统内使用通用访问进行此操作。嘿,谢谢您的回答;你能链接到鼠标定位工具吗?我尝试过各种谷歌搜索,比如鼠标定位shell脚本,但谷歌没有返回任何有用的hello。我很抱歉谷歌找不到鼠标位置。我在我的帖子中提供了一个更好的替代工具。HTHHi McUser,感谢您的帮助。我得到了一个错误:无法将MouseTools转换为integer类型。我会把我的代码粘贴在这里,但是太长了;但是我已经按照你的指示做了。你好。在使用MouseTools使用的路径在MouseTools前面加上前缀后,尝试在单独的脚本中执行这一行:log&do shell script,然后选择哪个MouseTools。在Applescript编辑器中查看日志。您的路径错误或丢失。您好,我收到的错误是:error无法将\MouseTools\转换为integer类型。数字-从鼠标工具到整数的1700
set mouseLoc to (do shell script "MouseTools -location")
set {astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
tell mouseLoc to set {mouseX, mouseY} to {it's text item 1, it's text item 2}
set {mouseX, mouseY} to {(mouseX as integer),(mouseY as integer)}