Как смоделировать перетаскивание с помощью applescript? Я создаю скрипт, который находит новейшее изображение в папке скриншотов и перетаскивает его и отбрасывает в слабое окно, чтобы оно было отправлено человеку, с которым я разговариваю.Моделирование перетаскивания с помощью applescript
ответ
@unska Я не знаком с Slack. Можете ли вы вставлять файлы из своего буфера обмена в незаполненное окно? Я думаю, что хорошим решением может быть создание AppleScript, который скопирует новейший файл скриншота в ваш буфер обмена, а затем вставляет клип-панель в слабое окно - wch1zpink вчера
@ wch1zpink copy paste действительно сработала. Мне нужно было отправить его после этого. Спасибо! - unska 16 часов назад
Я написал этот скрипт, который сделает снимок экрана, а затем скопируйте его в буфер обмена, затем активирует 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, чтобы отправить файл на слабину. Например: do shell script «curl -X POST --data-urlencode» payload = {... – jweaks
@jweaks, что эти ребята говорят здесь: https://discussions.apple.com/thread/5991137?tstart=0 – unska
Они достигают в темноте. У вас может быть приложение, открывающее файл, который не достигнет того, чего вы хотите. Вам придется использовать api. У вас может быть действие с папкой, прикрепленное к скрипту, но это означает, что вы физически перетаскиваете файл, который вы хотите избежать. – jweaks