How can I simulate drag and drop with applescript? I'm creating a script that finds the newest image in the screenshot folder and drag and drops it to the slack window so it gets sent to the person I'm having a conversation with.
#unska I'm not familiar with Slack. Can you paste files from your clipboard into a slack window? I'm thinking a good solution may be creating an AppleScript which will copy the newest screenshot file to your clipboard then pasting the clip board to the slack window – wch1zpink yesterday
#wch1zpink copy paste actually worked. I only had to send enter after it. Thank you! – unska 16 hours ago
I wrote this script which will take a screenshot, then copy it to your clipboard then that it will activate Slack and paste the screenshot into your message and send it.
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
In script editor, save this script as an application. Then you can make the application speakable and launch it with dictation commands and configure it to launch with a keyboard shortcut. You could also just run the application as it is.
Related
NOTE: I do not have Admin privileges, and cannot use things that require assistance or accessibility or whatever it is!
I'm basically trying to write an execution of a script that sets up my macOS Desktop by opening apps, positioning them etc
Part of that is allowing me to click continue on a dialogue after doing certain things I have to do manually as a result of the limitation (positioning a few apps for example).
I can successfully have the first alert pop up, and when I press OK, it executes the task, but then the 2nd alert is hidden behind AppleScript and will not pop up until I click AppleScript. Anyone know why?
Heres what I have, and please keep in mind I do not have Admin privileges, which means I can't use System Events:
tell application "Script Editor"
set miniaturized of window 1 to true
end tell
display alert "App is opening. Make sure you log-out of Apple Connect!"
delay 3
tell application "Safari"
activate
make new document
set the bounds of the front window to {1077, 23, 1581, 464}
tell window 1
set URL of tab 1 to "http://appwebsite.com"
end tell
end tell
display alert "Set up App, sign into Apple then click OK to open all other Safari windows"
delay 1
tell application "Test Task App" to activate
Place an activate command before the display alert command so Script Editor has focus and the display alert command will not be hidden.
Example:
activate
display alert "Set up App, sign into Apple then click OK to open all other Safari windows"
You do not need it before the first one as Script Editor has focus with it runs the first display alert command, but once you activate Safari, the display alert command is behind Safari. So if you use an activate command before the display alert command, it brings it forward in front of, in this case, Safari.
I often have a need to grab a screen shot of something on my screen (Since I am using OSX, I use the Command+Control+Shift+4 combination, which puts the screenshot into the clipboard). This works well, and allows me to paste into MS Word and other programs.
At some point I had an issue pasting into MS One Note (still on OSX), (I was not able to, when doing Command+V, nothing would paste), which I was able to solve researching online, by changing the default image type for screenshots (I think it was from JPG to PNG, using a command in the OSX terminal).
While this worked for MS One Note, it never helped with pasting into Gmail in Safari (note that I have no issues doing this in Google Chrome).
Can anyone help with how to get pasting images from the clipboard into Gmail when using the Safari Browser? (note I am using the latest OSX and Safari versions available).
Thanks!
I have never tried using the Command+Control+Shift+4 combination but this is what I usually use and it works perfectly for me.
Task 1;
to copy the screen capture to the clipboard so you can use Command+V to paste in any program of your choice
Open your terminal
Type this "screencapture -c" in the terminal without the quotes e.g.: screencapture -c
open any program of your choice and press Command+V to paste.
Task 2;
To screen capture your computer screen and save the file directly to a png or jpg and later insert or attach it to any program of your choice
Open your terminal
type this "screencapture ./Location/filename.ext" in the terminal without the quotes e.g.: screencapture ./Desktop/myCapture.jpg This will save the capture file on the desktop with the jpg format.
to get more information about the command, type "screencapture --h" in your terminal without the quotes.
There is currently no keyboard shortcut to play videos in the new Mac Photos application.https://discussions.apple.com/thread/6996731?start=0&tstart=0
Rather than be frustrated in manually clicking the "play" button hundreds of times, I would like to run an Applescript to play/pause with a keyboard shortcut. I tried with no success:
tell application "photos"
"play" video
end tell
Any help advice on this would be appreciated.
Thanks
Just to update Paul's response, in Photos 2.0 (3150.4.120), you need to hit TAB twice, then spacebar will start playback. Similarly you need to hit TAB twice once you are done playing it, and then (and only then) spacebar will take you back to the grid view of your thumbnails.
If you do not mind a slightly time-consuming workaround, you can enslave Automator to create a Service that will subsequently respond to a keyboard shortcut. You can find the instructions here.
Since your goal is to use the keyboard, there's a better option for you. After selecting a video with cursor keys or mouse, press space to maximize the video, and then press TAB. Then space will start the video playing, left and right arrows will move frame-by-frame. Hitting TAB again will allow the space bar to return the video to its normal size.
Apparently this changes the focus to the pane with the movie so that space can start it, or perhaps it changes focus to the movie controls? IMHO, whatever it does, it's not very intuitive and badly needs to documented and preferably fixed.
More info at:
https://discussions.apple.com/thread/6996731?start=0&
2020 / Photos 6.0:
You can now toggle playback with Option + Space
or do it manually via "Image" -> "Start Playback".
Autoplay Script
repeat while application "Photos" is running
delay 1
try
tell application "System Events"
tell process "Photos"
click menu item "Start Playback" of menu "Image" of menu bar 1
end tell
end tell
end try
end repeat
Save it as autoplay.scpt and run it with osascript autoplay.scpt.
The script exits when you close the Photos application.
I am looking for a tool that can 'stick' the OS X terminal app to the desktop background. I want it to be below the desktop icons, on top or instead of the background image.
I am using the terminal through out the day, from time to time. But I don't really need it for ongoing tasks, only to check something very fast. So having an active corner that shows the desktop would be the ideal guesture to reveal the terminal.
GeekTool has the ability to present the output of a terminal command on a desktop, however, I haven't been able to type something into the terminal overlay, GeekTool is showing. Is there any other tool, that could achieve that?
You can use the stock Script Editor app to save the following script as an application (.app file):
tell application "Terminal"
do script "cd ~/Desktop"
end tell
You can edit the script above to specify the directory you want the new window to use by default.
Once you've created your .app file you can put it on your desktop and conveniently double click it to open a new terminal window.
How can I open *.eml-files in compose mode for Mac OS X Mail? For Outlook "X-Unsent: 1" seems to do the trick, but does not work for Mac OS X Mail still opens in Read-Only.
This is a super old question, but obviously has received a fair number of views. My curiosity piqued, I figured I'd take a look. After some fiddling around, I found you can add the following header to make a message editable:
X-Uniform-Type-Identifier: com.apple.mail-draft
Add that to your otherwise RFC-2822 compliant message, give it a .eml or .emlx extension, and when you double-click it'll open as an editable message in Mail.app.
Have fun.
In macOS Catalina 10.15.7, running the following commands from a Python script worked to open a new message and then switch to compose mode, but there is a race condition between opening the message and putting it in Compose mode if the osascript command runs too quickly. The sleep command is there to prevent the race, but you may need to adjust the length of sleep time to compensate for this. (I also used time.sleep(1) in Python instead of the shell command.)
/usr/bin/open -a Mail path/to/tmp/message.eml
/bin/sleep 1
/usr/bin/osascript -e 'tell application "System Events" to tell application process "Mail"' -e 'keystroke "d" using {command down, shift down}' -e 'end tell'
Note that you must grant access to Terminal to control other apps, or the osascript command will fail with an error. To do that, open System Preferences, click on the Security & Privacy item, click Accessibility from the left menu, click the lock icon to unlock the menu, then check the Terminal item (or add it if not listed) in the "Allow apps to control your computer." list.
Also note that the Cmd-Shift-D keyboard shortcut sends a message that is already in compose mode, so if someone is using Mail at the time the script runs, and they have a separate compose window in the foreground, then the script could send that message instead of putting the new message in compose mode.