I run this script and applescript can detect the devices just fine
tell application "QuickTime Player"
video recording devices
end tell
It gives a the reply below
{screen compression preset "FaceTime HD Camera" of application "QuickTime Player", screen compression preset "Gangzheng's iPhone" of application "QuickTime Player"}
But when I run my actual script
tell application "QuickTime Player"
video recording devices
set newMovieRecording to new movie recording
tell newMovieRecording
set current camera of newMovieRecording to "Gangzheng's iPhone"
set current microphone of newMovieRecording to "Gangzheng's iPhone"
start
end tell
end tell
it says QuickTime Player got an error: Can’t make "Gangzheng's iPhone" into type video recording device.
Is there a way to make applescript record anything from iPhone?
I had accomplished what you want to do, but in a different way because I also tried with
set current camera of newMovieRecording to "Gangzheng's iPhone"
but had no luck.... So here is my script for setting a camera
tell application "System Events" to tell process "QuickTime Player"
#Set volume to 100%
click button 1 of window 1
#To open dialog to show available cameras
click button 3 of window 1
#To select our device
click menu item "Gangzheng's iPhone" of menu 1 of button 3 of window 1
end tell
My script was a bit longer because I wanted to record the screen of my iphone at my MAC... So I had to set QuickTime Player to full screen, move mouse pointer outside the screen and so on...
tell application "Finder"
set bigBounds to (get bounds of window of desktop)
end tell
tell application "QuickTime Player"
activate
start
#Start new recording cmd + option + N
tell application "System Events" to key code 45 using {option down, command down}
set iBounds to (get bounds of front window)
if bigBounds = iBounds then
delay 1
else
#Full screen only if is not already at full screen control + cmd + F
tell application "System Events" to key code 3 using {control down, command down}
delay 1
end if
tell application "System Events" to tell process "QuickTime Player"
#Set volume to 100%
click button 1 of window 1
#To open dialog to show available cameras
click button 3 of window 1
#To select our device
click menu item "iPhone de User" of menu 1 of button 3 of window 1
end tell
#To move mouse to the right side of the screen
set mouseToolsPath to "/Users/Shared/MouseTools"
set x to (item 3 of bigBounds) - 1
set y to (item 4 of bigBounds) / 2
#Por si el archivo no existe...
try
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (x as text) & " -y " & (y as text)
on error errMsg number errNum
display dialog "An unknown error occurred: " & errNum as text
end try
end tell
Hope it is helpful to someone.
barbudito, can you try this?
tell application "QuickTime Player"
get video recording device "Gangzheng's iPhone"
set newMovieRecording to new movie recording
tell newMovieRecording
start
delay 10
do shell script "env"
pause
save newMovieRecording in "/Users/pmlg673f/Movies/test.mov"
stop
close newMovieRecording
end tell
end tell
I had encountered this exact problem and made the following blog post which covers how I solved it https://kevinjalbert.com/applescript-that-mirrors-iphone-to-quicktime/. I had used some inspiration from this post and others as I looked around for a way to set the video/audio inputs via AppleScript.
The source for the AppleScript is here: https://gist.github.com/kevinjalbert/d7661a6a34c1d66dccf701f64eb09be4#file-mirror-scpt.
Related
Im trying to make an AppleScript that takes a picture of by taking a screenshot of photoBooth. However, I cant set the window to one. Heres my code:
tell application "Photo Booth"
activate
set volume output volume 0
tell application "Finder" to set visible of process "Photo Booth" to false
set windowid to id of window 1 of application "Photo Booth"
do shell script "screencapture -l" & windowid & " ~/test.png"
tell application "Photo Booth"
end tell
delay 0
quit
end tell
I am unsuccessfully trying to use AppleScript to automate the process of making small edits to a bunch of files. More specifically, I want a script that will:
Open a specific file in QuickTime
Split it into segments of a specified length
Save each segment as an individual file in the same format and with the same quality as the original.
Close the document
Most importantly, I want the script to essentially work unassisted/unmanned.
Here's some more info on what I'm trying to do: http://hints.macworld.com/article.php?story=20100305070247890.
Another user on StackOverflow asked a similar question a while back, but the suggestion does not work.
From the few online discussions I've been able to find, it appears that Apple took away some of the functionality of QuickTime after version 7. I'm currently using 10.3+
Here's another discussion that describes almost exactly what I'm trying to do. As "kryten2" points out, export no longer seems to work in the new version of QuickTime. And, just like "VideoBeagle", I get permissions errors when I try to call the save method.
The code posted by VideoBeagle on that page does not work for me. Here's a modified version:
tell application "QuickTime Player"
open basefile --argument passed to script when executed
set the clipboard to "outputfile"
delay (0.25)
tell document 1
trim from 0 to 60
tell application "System Events"
tell process "QuickTime Player"
keystroke "s" using command down
keystroke "v" using command down
delay 1
keystroke return
delay 3
#click menu item "Save..." of menu "File" of menu bar 1
end tell
end tell
close saving no
end tell
end tell
The code above DOES open the file in QuickTime and trims the file to the correct length, but then it creates an unsaved copy of the file in a new window, closes the original, but does not save the new document. When I experiment with the delay and remove the "trim" function, it will show the Save dialog but won't actually save a file.
Has anyone successfully managed to use AppleScript and QuickTime to save files? ...recently?
Thank you so much!
The best should be to use export function of QuickTime Player 7 if you have the QuickTime Pro authorization (not free, but very cheap). to do so, you also need to download this old QT version from Apple site. it is still available, but Apple promotes the QuickTime Player 7 with basically only read functions.
Still if you want to stick to QuickTime Player (after version 7), there are known issues in scripting while saving. The workaround is to simulate part of GUI as you already start doing.
The script bellow asks for movie file to be processed, defines the new path and name for the modified video, trim from second 2 to second 6 and then use the GUI interface to save and close. I made many comments to make sure you can understand and update for your own needs :
-- select file to be processed
set myVideo to choose file with prompt "Select video to be processed"
-- set new path and file name
set newPath to ((path to desktop folder from user domain) as string) & "Test_Folder"
set PPath to POSIX path of newPath
set newName to "cutVideo.mov"
tell application "QuickTime Player"
activate
open myVideo
set myDoc to front document
trim myDoc from 2 to 6 -- keep only video from second 2 to 6
end tell
tell application "System Events"
tell process "QuickTime Player"
keystroke "s" using {command down}
delay 0.8
keystroke "G" using {command down} -- go to
delay 0.8
keystroke PPath -- folder path with / and not :
delay 0.8
keystroke return
delay 0.8
keystroke newName -- fill file name
delay 0.8
keystroke return -- ok save dialog
delay 0.8
keystroke "w" using {command down} -- close window
end tell
end tell
Writing an AppleScript to open Image Capture and click the Import All button.
tell application "Image Capture"
activate
tell application "System Events"
tell process "Image Capture"
click button "Import All" of group 1 of splitter group 1 of window 1
end tell
end tell
end tell
Image Capture opens but the script throws an error message saying it couldn't find the button "Import All".
Have followed advice on other threads on how to check the location in Accessibility Inspector and how to translate that to AppleScript instructions.
What's missing?
To get the button and group numbers, you have 2 ways: use the utility aplication provided by Apple in the developper toolkit "Accessibility Inspector" or use small scripts to find the number yourselves.
I prefer using script method. it is a bit longer sometime, but it always works. Just write a script with instruction get UI elements. Here is a small example of such script:
-- return lis of UI elements of active application and paste result in Excel
property tab : ASCII character 9
global T
-- to find last active application
tell application "System Events"
set frontmostProcess to first process where it is frontmost
set visible of frontmostProcess to false
repeat while (frontmostProcess is frontmost)
delay 0.2
end repeat
set secondFrontmost to name of first process where it is frontmost
set frontmost of frontmostProcess to true
end tell
set ActifProcess to secondFrontmost as text
tell application ActifProcess to activate -- set active the last actived application
delay 1
-- recursive loop to list all elements of active window
tell application "System Events" to tell process ActifProcess to set myWindow to front window
set T to ""
getUI(myWindow, 1)
set the clipboard to T
display dialog "Result is in clipboard. paste in Excel or text document"
on getUI(UIObjet, myLevel) -- get recursively the list of UI elements
set AppleScript's text item delimiters to {"//"}
tell application "System Events" to set UIliste to UI elements of UIObjet
repeat with oneUI in UIliste
tell application "System Events"
set UItext to ("Level=" & myLevel & tab & "Name=" & (name of oneUI) & tab & (description of oneUI) & tab & "Class=" & (class of oneUI) as string) & tab & "Title=" & (title of oneUI) as string
set UItext to (UItext & tab & "Value=" & (value of oneUI) as string) & tab
try
set UItext to (UItext & "Position=" & (position of oneUI) as text)
end try
set UItext to UItext & return
try
set NbSub to count of UI elements of oneUI
on error
set NbSub to 0
end try
set T to T & return & UItext
end tell
if NbSub > 0 then
getUI(oneUI, myLevel + 1) -- there are other sub UI elements, get them
end if
end repeat
end getUI
Copy this script in Script Editor. Make active the window/application you want to get UI elements. Make this script active and run.
The result is sometime not easy to interpret because developper of the application/window you're looking for may not have use UI element clear names or titles which describe what they are. Then you will have to look their relative position in the window.
The "import all" button is "button 3 of group 2 of splitter group 1 of window 1" for image capture version 6.6. Also, I prefer to use button number, instead of button name to make sure the script works with any language.
tell application "Image Capture"
activate
tell application "System Events"
tell process "Image Capture"
click button 3 of group 2 of group 1 of splitter group 1 of window 1
end tell
end tell
end tell
Please note that any next changes done by Apple on Image Capture will impact your script.
I'm using the following AppleScript to determine when the user clicks the stop recording button in the task bar:
tell application "QuickTime Player"
tell document 1
activate
new screen recording
delay 1
tell application "System Events" to key code 49
delay 2
repeat until (new screen recording) is false
end repeat
end tell
end tell
Though instead the script keeps relaunching QuickTime.
You can put the result of the new screen recording command into a variable.
Use the exists command to check this document
tell application "QuickTime Player"
activate
set tdoc to new screen recording --> document "Screen Recording"
delay 1
tell application "System Events" to key code 49
delay 2
repeat while exists tdoc
delay 1
end repeat
-- the recording is stopped
tell front document
-- do something with the front document ("Untitled")
end tell
end tell
I am trying to play a movie fullscreen one time, then close the player programmably.
I have tried using QTMovieView, command line and AppleScript and found the Applescript is the most simple way.
BUT, as I really don't know Applescript, I can not make the QuickTime auto close after movie playing.
Everything works fine but the "done" was unrecognized in the repeat line.
Here is the script with this error:
error "QuickTime Player got an error: Can't make done of document 1 into type specifier." number -1700 from done of document 1 to specifier
tell application "QuickTime Player"
activate
open "/Users/...real path of the movie.mov"
present document 1
play document 1
repeat until (get done of document 1)
end repeat
delay 2
close document 1
end tell
Finally, I changed to this, is this ok?
tell application "QuickTime Player"
quit
end tell
tell application "QuickTime Player"
activate
open "/Users/.../...mov"
tell document 1
present
play
repeat until playing is false
end repeat
delay 2
close
end tell
quit
end tell
New problem: app hang before video finish.
This works for me, however it doesn't seem very robust. Is it guaranteed that the current time will always end up being equal to the duration, given that they're both reals? You may want to put some "within epsilon" logic into the repeat condition.
tell application "QuickTime Player"
play document 1
repeat until (current time of document 1 = duration of document 1)
end repeat
delay 2
close document 1
end tell
Try:
tell application "QuickTime Player"
tell document 1
present
play
repeat until playing is false
delay 1
end repeat
end tell
quit
end tell