用applescript模拟拖放
如何使用applescript模拟拖放?我正在创建一个脚本,在screenshot文件夹中找到最新的图像,并将其拖放到slack窗口,以便将其发送给与我对话的人用applescript模拟拖放,applescript,Applescript,如何使用applescript模拟拖放?我正在创建一个脚本,在screenshot文件夹中找到最新的图像,并将其拖放到slack窗口,以便将其发送给与我对话的人 @unska我对Slack不熟悉。你能把剪贴板上的文件粘贴到一个松弛的窗口中吗?我认为一个好的解决方案可能是创建一个AppleScript,将最新的屏幕截图文件复制到剪贴板,然后将剪贴板粘贴到slack窗口–wch1zpink昨天 @wch1zpink复制粘贴实际上有效。我只需要在它之后发送enter。谢谢16小时前的unska 我写了
@unska我对Slack不熟悉。你能把剪贴板上的文件粘贴到一个松弛的窗口中吗?我认为一个好的解决方案可能是创建一个AppleScript,将最新的屏幕截图文件复制到剪贴板,然后将剪贴板粘贴到slack窗口–wch1zpink昨天
@wch1zpink复制粘贴实际上有效。我只需要在它之后发送enter。谢谢16小时前的unska 我写了这个脚本,它将截图,然后复制到你的剪贴板,然后它将激活Slack,并粘贴到你的消息截图,并发送它
do shell script "screencapture -c" -- This takes a screencapture and copies it to the clipboard.
-- Below, I added the different usage examples for screencapture right from the man page in Terminal
(*
usage: screencapture [-icMPmwsWxSCUtoa] [files]
-c force screen capture to go to the clipboard
-b capture Touch Bar - non-interactive modes only
-C capture the cursor as well as the screen. only in non- interactive modes
-d display errors to the user graphically
-i capture screen interactively, by selection or window
control key - causes screen shot to go to clipboard
space key - toggle between mouse selection and
window selection modes
escape key - cancels interactive screen shot
-m only capture the main monitor, undefined if -i is set
-M screen capture output will go to a new Mail message
-o in window capture mode, do not capture the shadow of the window
-P screen capture output will open in Preview
-I screen capture output will in a new Messages message
-s only allow mouse selection mode
-S in window capture mode, capture the screen not the window
-t<format> image format to create, default is png (other options include pdf, jpg, tiff and other formats)
-T<seconds> Take the picture after a delay of <seconds>, default is 5
-w only allow window selection mode
-W start interaction in window selection mode
-x do not play sounds
-a do not include windows attached to selected windows
-r do not add dpi meta data to image
-l<windowid> capture this windowsid
-R<x,y,w,h> capture screen rect
-B<bundleid> screen capture output will open in app with bundleidBS
files where to save the screen capture, 1 file per screen
*)
delay 2
tell application "Slack"
activate
delay 5 -- this gives you time to put your cursor in the window where you want to paste your screencapture. This was the only option I could think of because I do not have Slack so I do not know any of the UI elements or window names as to where to tell this script where to place the screencapture.
tell application "System Events"
key code 9 -- this will paste the screencapture from your clipboard into the active Slack window where your cursor is.
delay 1
key code 36 -- this should press the return key and send your message
end tell
end tell
在脚本编辑器中,将此脚本另存为应用程序。然后,您可以使应用程序可说话,并使用听写命令启动它,并将其配置为使用键盘快捷键启动。您也可以按原样运行应用程序。as无法拖动文件。您必须使用几个可用的api之一将文件发送到slack。类似这样的东西:shell脚本curl-X POST-data urlencode'payload={…@jweaks这些家伙在这里说什么:他们在黑暗中到达。你可以让一个应用程序打开一个文件。这不会达到你想要的效果。你必须使用api。你可以在脚本上附加一个文件夹操作,但这意味着你要实际拖动一个文件,这是你想要避免的。@unska我不熟悉Slack。你能把剪贴板上的文件粘贴到slack窗口吗?我认为一个好的解决方案可能是创建一个AppleScript,将最新的截图文件复制到剪贴板上,然后将剪贴板粘贴到slack窗口window@wch1zpink复制粘贴确实有效。我只需要在它之后发送enter。谢谢!