How do I change the quicktime document current camera to a different camera in AppleScript?
I want the script to automatically switch to my iphone and then record a video.
I have it done so that it's using system events clicks but this way is slow and clunky.
tell application "QuickTime Player"
activate
tell application "System Events"
activate
tell process "QuickTime Player"
click menu item "New Movie Recording" of menu "File" of menu bar 1
set cameras to button 3 of window 1
click cameras
delay 0.5
click menu item 3 of menu 1 of cameras
end tell
end tell
delay 2
tell (document 0)
start
delay 3
stop
end tell
end tell
As per the QuickTime Player scripting library, you can retrieve a list of video recording devices using the command:
get [id, name] of video recording devices
which will return something like:
{{"CC26302Z3U5H0X0FP", "iGlasses"}, {"FaceTime Camera", "iGlasses"}}
corresponding the id and name of each camera, respectively. Each movie recording has a bunch of properties, one of which is called current camera, which is of type video recording device. This property is both readable and settable, in theory.
Therefore, one ought to be to do this:
set R to new movie recording -- creates new recording
set current camera of R to video recording device named "iGlasses"
However, this command does absolutely nothing. Indeed, when I try and read the value of the property, using get current camera of R, it returns missing value.
So, my feeling is that this feature has yet to be implemented properly into AppleScript, or there's a bug in QuickTime Player.
Doing a quick Google now reveals lots of people have encountered this problem and others have come to the same conclusion as I, e.g. here.
Other people's suggestions all seem to resort to GUI scripting, which I share your feelings about.
Sorry this isn't the answer you were hoping for.
Related
I'm a uni student taking online courses, I take portion screenshots by pressing Command+Control+Shift+4 every time to take notes, then I paste it to Notion. But it's not efficient to select the same area every time, then I found that QuickTime Player will keep the same area for capturing a portion screenshot, so I decided to use Apple Script to complete the operation.
The code I wrote could switch to the application QuickTime Player and then proceed to "New Screen Recording" in the menu by pressing Command+Control+N, but the problem is that sometimes pressing twice space will call out "Capture Selected Window" instead of "Capture Selected Portion". Meanwhile, the location where saving the screenshots will also be changed too though I already ticked "Remember Last Selection", maybe resetting the location to be saved every time is essential.
on run {input, parameters}
activate application "QuickTime Player"
tell application "System Events"
key code 45 using {command down, control down}
delay 0.1
# Switch to "Capture Select Portion" by pressing SPACE
repeat 2 times
key code 49
delay 0.1
end repeat
# Press ENTER to capture a screenshot
key code 35
delay 0.1
end tell
return input
end run
I spent a few hours finding the existed articles but perhaps not that fulfill my needs.
do shell script "screencapture -ci" is as same as pressing Command+Control+Shift+4, and I have to select the portion manually.
do shell script "screencapture -x -R20,20,640,380 ~/Desktop/test.png" needs a precise coordinate. But the coordinate is variable since the window is not fixed, and it needs to be found by using external software, maybe it's a little bit not efficient. If there is no solution for that, I will use it since it's much more convenient than selecting the portion every time.
Sorry about pasting others' code here and saying why they r not suitable for me, I just wanted to make it clear... Thanks for reading here, have a nice day no matter if u r willing to help me ^ ^
The part about pasting screenshots to Notion works, so I didn't paste it here.
I tried writing something, it works but still has some bugs.
For example, the coordinate of the menu "Options" should be initialized depending on the precise location of the bar since I didn't succeed in finding the element by using entire contents.
You can't move your mouse during the use, or it might cause an error:
System Events got an error: Can’t get menu \"Options\" of button \"Options\" of window \"Window\" of application process \"screencaptureui\"." number -1728 from menu "Options" of button "Options" of window "Window" of application process "screencaptureui
When selecting the path where screenshots will be saved, it might take a few seconds to let the program find the menu item Clipboard.
tell application "System Events"
tell process "QuickTime Player"
# Switch to QuickTime Player (already opened expected, no launching time reserved)
activate
# Open "New Screen Recording" from the menu
click menu item "New Screen Recording" of menu "File" of menu bar item "File" of menu bar 1 of application process "QuickTime Player" of application "System Events"
delay 1
end tell
# Capture Selected Portion
tell application process "screencaptureui"
click checkbox "Capture Selected Portion" of window "Window" of application process "screencaptureui" of application "System Events"
# Select Options from the menu (idk why if I replace it with click menu, the clipboard won't be found, needs to be fixed)
click at {817, 824}
delay 0.1
# Save to the Clipboard
click menu item "Clipboard" of menu "Options" of button "Options" of window "Window" of application process "screencaptureui" of application "System Events"
delay 1
end tell
# Enter to capture the screenshot
key code 36
delay 0.1
# Switch to Notion (already opened expected, no launching time reserved)
tell application "Notion"
activate
delay 0.1
end tell
# Paste the screenshot to Notion
key code 9 using {command down}
end tell
Hope this helps someone, if u hv any idea plz feel free to modify it since it still has bugs.
The following script will open a track in iTunes
use application "iTunes"
property trackURL : "itmss://itunes.apple.com/us/album/brahms-violin-concerto-in-d-major-op-77-iii-allegro/145533236?i=145533044&uo=4"
open location trackURL
Now, asking "iTunes" to play it does not work because the track is highlighted but not properly selected, i.e., it requires a manual mouse click to select it and play it.
How can I select the highlighted track? Or how could I ask "iTunes" to play the song?! Alternatively, is there a way to add a music to my library from an URL directly?
Disclaimer: I don't have the Apple Music subscription, so the UI on my end may not be exactly the same as yours. However, if I click the "Play" button, I get the little advertisement asking me to sign up for the service, which I assume would just play the music if you had the service. So, these are the steps I've been able to follow to get that box to pop up:
The first, and most convenient from AppleScript, thing to try is just to hit the space bar to start the music playing. This actually works great if I've selected the item manually by clicking on it. However, after open location, it doesn't work, and this appears to be because even though the row is highlighted in the viewer, the actual keyboard focus seems to be on the page itself (the iTunes Store and Apple Music appear to have their entire UI presented as web pages rendered by WebKit). You can verify this by tapping the up and down arrow keys on the keyboard; the page scrolls up and down instead of you switching to adjacent tracks.
My opinion is that this is actually a bug in iTunes; I'd consider the true solution to the problem to be to report this to Apple via the bug reporter. Using open location really should set the keyboard focus to the track you navigated to.
With that said, we can work around it in the short term by simulating a click on the "Play" button. Note that you'll probably need to add your app in System Preferences > Security and Privacy > Accessibility. Note also that this is incredibly fragile, and if Apple ever changes anything in the layout of the web pages they're serving, this whole thing will break. Finally, please note that this code is extremely ugly; the whole thing gives me hives just by looking at it, but it's the only thing I was able to get to work. Side effects of reading this code may include nausea, headaches, and suicidal thoughts. Do not read this code immediately after eating. Consult your doctor before reading this code if you have a history of depression or obsessive-compulsive disorder.
property trackURL : "itmss://itunes.apple.com/us/album/brahms-violin-concerto-in-d-major-op-77-iii-allegro/145533236?i=145533044&uo=4"
property trackTitle : "III. Allegro giocoso, ma non troppo vivace"
tell application "iTunes"
activate
open location trackURL
delay 1 -- give the page a second to load
end tell
tell application "System Events"
tell process "iTunes"
set theRows to the rows of table 1 of UI element 1 of scroll area 1 of group 1 of group 1 of front window
-- "repeat with eachRow in theRows" isn't working. I don't know why. Freaking AppleScript
repeat with i from 1 to the number of theRows
set eachRow to item i of theRows
if exists group 2 of UI element 2 of eachRow then
if value of static text 1 of group 1 of group 2 of UI element 2 of eachRow is trackTitle then
tell group 1 of UI element 2 of eachRow to click
end if
end if
end repeat
end tell
end tell
If Apple ever fixes the bug, of course, we should be able to just:
tell application "iTunes"
activate
open location trackURL
delay 1 -- give the page a second to load
end tell
tell application "System Events" to keystroke space
I need a simple AppleScript that will cause PowerPoint to move to a specified slide number. I unfortunately am not familiar enough with AppleScript to properly interpret the information in the Applescript Library for PowerPoint. I think if someone can get me started I can take it from there.
The script just needs to reference the active presentation. If I could speak to my computer I just need to tell it to "go to slide #5" or "go to slide #2", etc.
The script needs to work while in Slideshow mode as the presentation will be running on a separate screen. Thanks so much for the help, I haven't been able to find this anywhere.
my gotoSlide(2)
on gotoSlide(whichSlide)
-- whichSlide is the integer position of the slide
tell application "Microsoft PowerPoint"
activate
tell active presentation
set theView to view of document window 1
go to slide theView number whichSlide
end tell
end tell
end gotoSlide
I'm using an applescript within automator to start a quicktime recording. When I run the applescript from automator, everything works fine, but when I run the same automator sequence as a double-clickable application, it throws an error* when it gets to this line:
tell application "System Events" to tell process "QuickTime Player" to set position of front window to {1131, 725}
Any ideas as to why?
Thanks!!
*The error is just, "The action “Run AppleScript” encountered an error"
You might be getting the error because your application doesn’t have permission to access GUI Scripting.
However, you can position and resize windows in QuickTime Player without GUI scripting like this:
tell application "QuickTime Player"
tell window 1
set the bounds to {100, 100, 640, 480}
end tell
end tell
The 4 numbers that set the bounds are the x position, y position, window width, window height. So the above script tells the first window to position itself 100 pixels away from the top of the screen, 100 pixels away from the left of the screen, and to be 640 pixels wide and 480 pixels tall.
Look in QuickTime Player’s AppleScript dictionary for the commands that enable you to start a recording with AppleScript. Open the Script Editor app and choose File > Open Dictionary and choose QuickTime Player.
I've successfully managed to get AppleScript to manipulate the background colors in my Numbers document by refering to the background color property. However, I would like to set the borders of a selection or range of cells as well.
I've looked in the Dictionary in AppleScript Editor for a command or property that could help me out here, but I haven't found anything. Is it the case that it's not possible to create borders in Numbers with AppleScript?
There is nothing in the AppleScript dictionary to allow this functionality (which is awful, IMO, but perhaps Apple will add this in the future if enough people complain).
You can use SystemEvents to interact with the interface of Numbers to add the borders:
-- Set the selection range
tell application "Numbers"
make new document
tell front document to tell active sheet to tell table 1
set selection range to range "A3:C6"
end tell
end tell
-- Asks System Events to interact with the interface
tell application "System Events" to tell application process "Numbers"
-- Asks the main window to click on the button called 'Cell' (the name depends of your system language)
tell window 1
click radio button "Cell" of radio group 1
-- Scroll area 4 is the inspector area
tell scroll area 4
-- The first incrementor of the inspector is the borders' one.
increment incrementor 1
end tell
end tell
end tell
If you want to manipulate other elements of the interface, I recommend using the Accessibility Inspector app that comes with Xcode.