0
如何用蘋果模擬拖放操作?我正在創建一個腳本,在屏幕截圖文件夾中找到最新的圖像,然後將其拖放到鬆弛的窗口,以便將其發送給正在與之交談的人員。用蘋果模擬拖放操作
如何用蘋果模擬拖放操作?我正在創建一個腳本,在屏幕截圖文件夾中找到最新的圖像,然後將其拖放到鬆弛的窗口,以便將其發送給正在與之交談的人員。用蘋果模擬拖放操作
@unska我不熟悉Slack。你能否將剪貼板中的文件粘貼到鬆弛的窗口中?我在想一個好的解決方案可能是創建一個AppleScript,它會將最新的截圖文件複製到剪貼板,然後將剪貼板粘貼到鬆弛窗口 - wch1zpink昨天
@ wch1zpink複製粘貼實際上工作。我只需要在它之後發送輸入。謝謝! - 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之一來發送文件。這樣的東西:做shell腳本「curl -X POST --data-urlencode'payload = {... – jweaks
@jweaks這些傢伙在這裏談論什麼:https://discussions.apple.com/thread/5991137?tstart=0 – unska
它們在黑暗中到達,你可以讓一個應用程序打開一個文件,但這不會達到你想要的,你必須使用一個API,你可以在腳本上附加一個文件夾操作,但是意味着你在物理上拖動了一個你想要避免的文件 – jweaks