I have a very basic applescript that starts a QuickTime screen recording (or rather opens up the screen recording dialog box in QuickTime):
tell application "QuickTime Player"
new screen recording
end tell
How do I make a second applescript that stops the screen recording and opens up a Save As... dialog box in QuickTime?
This is a simple example of how to accomplish stopping a recording already underway and present the Save... dialog box (note that most if not all versions of QuickTime Player have a Save... option and not Save As...)
tell application "QuickTime Player"
new screen recording
delay 5
-- press record button
end tell
tell application "System Events"
-- stop the recording
key code 53 using {command down, control down}
-- wait for recorded window to appear
delay 5
keystroke "s" using command down
end tell
The answer to your question is the second tell block but I included the first tell block so that you can run this script as is and see the entire process in action.
The delay in the second tell block is so that the Save... command is not fired before QuickTime Player finishes rendering the screen recording and opening the video in a window, otherwise the Save... dialog box won't appear in the foreground or possibly won't appear at all.
Ideally this script should be developed further to wait until the screen recording has been rendered and opened in a window, rather than using a delay, but it answers your question in the most basic form.
Related
I would like to control VLC Media Player using hotkeys while typing in Word or Pages (without having to have VLC Media Player be the active window).
Can I use AppleScript to do this? I am editing video transcripts and, at the moment, have to toggle between programs to control the active window. I would love to be able to press hotkeys to:
rewind
jump back 5 seconds
play/pause
fast forward
jump forward 5 seconds
Thank you so much for any help you can offer. I've never used AppleScript and appreciate any help.
I used a free hotkey assigner called Spark and inserted Applescript for these functions, following a tutorial on how to do this for transcription, but it didn't work. (I did it for Quicktime but would actually prefer to use VLC Media Player. Either would be great, though).
https://www.engadget.com/2008-06-26-simplify-media-transcription-with-hotkeys-and-applescript.html
Jump back:
tell document 1 of application "QuickTime Player" to set current time to (current time - 2500)
Play/pause:
tell document 1 of application "QuickTime Player"
if playing is true then
pause
else
start
end if
end tell
Jump forward:
tell document 1 of application "QuickTime Player" to set current time to (current time + 2500)
I have written this piece of code on my MAC OS X 10.10.5 to automate keystrokes on a window that pops up within Firefox.
It does not work reliably and, in many cases, performs the keystrokes on the window in the background. I have tried increasing the delay but it does not seem to be related to timing. The problem, instead, seems to be that the wrong Firefox window is activated.
This is my code. Any ideas on how I can fix it to work reliably.
set myBrowser to "/Applications/Firefox.app"
tell application myBrowser
activate window 2
end tell
tell application "System Events"
keystroke tab
delay 2
keystroke enter
end tell
If Firefox opens up a pop-up window, I believe that window now becomes window 1. The system events will be sent to that front pop-up window. Try using this code
activate application "Firefox"
tell application "System Events"
delay 2
key code 48
delay 1
key code 36
end tell
I'm trying to fix a particular problem in this Applescript I made: https://gist.github.com/jwmann/08daed8a905cfbf4ff96
Context:
It's an Applescript where you select a song in a VLC playlist, run the Applescript and it will trash the song from the original location.
The Problem:
The problem occurs when a user attempts to delete a currently playing, single song where the VLC playlist is the size of just the single song.
Now VLC will explode if you try to delete a song that it's currently playing. To workaround this I've made the script stop VLC from playing and trying again to delete it.
Now if this workaround happens, VLC will no longer be playing. In a multi-song playlist, this can't be annoying. So the script will continue playing VLC at the end of the script. However, after deleting the song from a single song playlist, it will remove the song from the playlist, leaving no songs and therefore no playlist.
So when the script tries to play, it'll open a new window / dialog / modal to allow the user to find something to play. This is something I don't want to happen.
What I'm trying to do:
I need a way to:
Detect the correct Window
Tell that window to Close
Information I've gathered:
This is the window I'm trying to Cancel
This is the data that Accessibility Inspector shows me about the window.
<AXApplication: “VLC”>
<AXWindow: “Open Source”>
Attributes:
AXFocused: “0”
AXFullScreen: “0”
AXTitle: “Open Source”
AXPosition (W): “x=993 y=276”
AXGrowArea: “(null)”
AXMinimizeButton: “(null)”
AXDocument: “(null)”
AXSections (W): “<array of size 1>”
AXCloseButton: “(null)”
AXMain: “0”
AXFullScreenButton: “(null)”
AXProxy: “(null)”
AXDefaultButton: “<AXButton: “Open”>”
AXMinimized: “0”
AXChildren: “<array of size 8>”
AXRole: “AXWindow”
AXParent: “<AXApplication: “VLC”>”
AXTitleUIElement: “<AXStaticText>”
AXCancelButton: “<AXButton: “Cancel”>”
AXModal: “1”
AXSubrole: “AXDialog”
AXZoomButton: “(null)”
AXRoleDescription: “dialog”
AXSize: “w=574 h=402”
AXToolbarButton: “(null)”
AXFrame: “x=993 y=276 w=574 h=402”
AXIdentifier: “_NS:40”
Actions:
AXRaise - raise
Things I've tried:
tell application "System Events"
close window "Open Source" of application "VLC"
end tell
tell application "System Events"
click button "Cancel" of window "Open Source" of application "VLC"
end tell
tell application "System Events"
cancel window "Open Source" of application "VLC"
end tell
tell application "System Events" to tell (window 1 of application "VLC" whose subrole is "AXDialog") to close
In every example, System Events or VLC (I tried both) can't seem to find the window "Open Source" even though it's clearly called "Open Source" in the inspector. It's not a sheet, it's a window. I don't understand why I can't find this window.
Thanks to #l'L'l for recommending me Script Debugger 5, it allowed to view the data of the windows in a readable way and even provide code on calling specific elements.
How I found out was I ran this code:
tell application "VLC" to activate
tell application "System Events"
tell process "VLC"
set myUI to every UI element
end tell
end tell
The reason being is that even though I knew the window's name, Applescript couldn't ever find it, so I needed a way to see everything.
Within that, I found this:
If you look at the metadata of this window, you'll see that it's SUPER broken.
No wonder Applescript could never find it, it's barely a window.
From that list, it provides the exact code to reference parts of the window, including, the "Cancel" button.
This is the code that cancels my window:
tell application "System Events"
tell its application process "VLC"
tell its window "Open Source"
click button "Cancel"
end tell
end tell
end tell
So searching every UI Element was definitely useful and Script Debugger 5 definitely helped.
I am currently working on a school project in which I need to open a video file while using a key press in applescript. I want the program to open the file fullscreen in quicktime player when I press "y" while the program is running.
This is my current code, it works but I don't see how I can include keypresses.
tell application "QuickTime Player"
set testmovie to "Users:Nan:movies:atime.mp4"
activate
open alias testmovie
play document 1
set presenting of document 1 to true
end tell
I hope you guys can help!
You can create a Service in Automator and paste your code within a run applescript action. You can then assign a keystroke to the service in keyboard preferences.
I've searched high and low to find a solution for this but have come up trumps.
I have a simple Applescript to wait for a minute, before opening a browser in fullscreen mode. (Allowing MAMP to startup as well).
The problem I face is, "Finder" has focus, and when the Applescript goes to execute the fullscreen command 'keystroke f {command down, shift down} it opens the "All Files" dialog, rather than the desired, Browser focused, enter fullscreen.
Does anyone know how to get around this please?
Couldn't you also activate the target application before entering full screen?
delay 10
tell application "Safari"
activate
reopen
end
tell application "System Events" to tell window 1 of process "Safari"
perform action "AXPress" of (button 1 where subrole is "AXFullScreenButton")
end tell
keystroke tab using {command down}
delay 1
keystroke "f" using {command down, shift down}
This works in my instance as the Finder had focus, and the next open application was my browser, which was the one I wanted to have focus. So if I were to do this manually I would hold COMMAND and press TAB once, to get the focus of the 'next app'
I'm not sure that the delay is required, but I added a 1 second delay just to make sure that the browser had focus, and then I execute the keystrokes to invoke fullscreen mode!