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
Related
I have a script automating a user interface of a third party app. In the script, there is a progress bar that shows up in the Script Editor as it should. But it does not show as a dialog box when I export the script as an app and launch it.
The third party app has it's own dialog boxes, I wonder if they interfer with the progress dialog box from the script.
Can you tell what is wrong?
repeat with idx from 1 to length of myList
set progress total steps to length of myList
set progress completed steps to idx
set progress description to "Processing media..."
set progress additional description to "Converting " & mediaName
tell application "System Events"
tell application process myApp
tell window myApp
--Things happening here
end tell
end tell
end tell
end repeat
Example with Handbrake's window, because I still should guess what app and window you use.
set mediaName to "myMedia"
set myApp to "HandBrake"
set myList to {"Marlow", "Maddie", "Sammy", "Stuey", "Jessie", "Tolstoy"}
set progress total steps to length of myList
set progress description to "Processing media..."
set progress additional description to "Converting " & mediaName
repeat with idx from 1 to length of myList
tell application "System Events" to tell process myApp
set frontmost to true
tell window 1
-- Things happening here
set a to value of static text 1 of group 1
display notification text 1 thru 20 of (paragraph 2 of a)
end tell
end tell
set progress completed steps to idx
tell me to activate
delay 3
end repeat
NOTE: you can't run progress window always on foreground because you want retrieve some info from other window using GUI scripting.
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.
Currently I have this working code:
on run
set info to ""
tell application "System Events"
set num to count (every process whose name is "iTunes")
end tell
if num > 0 then
tell application "iTunes"
if player state is playing then
set albumName to (get album of current track)
end if
end tell
end if
return text 1 thru 10 of albumName
end run
if running iTunes and live albums are formatted correctly (YYYY-MM-DD) - this will bring back the date of a live album. I'd like to now take the result of "return text 1 thru 10 of albumName" and add it to this code:
tell application "Firefox" to activate
tell application "Firefox"
open location "http://someband.com/showID=" & *[insert code for "text 1 thr 10 of albumName" variable]*
end tell
I know the "&" isn't correct but I thought that was the start. The way this should work is if I'm listening to "2013-03-12 Live on StackOverflow" I want the script to take "2013-03-12" and append it to my link so Firefox opens website address: "http://someband.com/showID=2013-03-12"
...make sense? Any help would be greatly appreciated. Thank you!
Try:
if application "iTunes" is not running then return
tell application "iTunes"
if player state is playing then
set albumName to (get album of current track)
end if
end tell
set myText to text 1 thru 10 of albumName
-- Assuming Firefox is your default browser…
open location "http://someband.com/showID=" & myText
I am trying to write an applescript script that resizes all open windows. In order to make sure that I'm getting to all the windows, I'm making my script say the name of the application as well as the number of open windows of that application.
Interestingly, while I hear the names of all my open applications, my script says that they all have 0 windows open. How can I fix this issue?
Here's my code:
tell application "System Events"
repeat with theProcess in (every process)
if background only of theProcess is false then
if name of theProcess is not "Finder" then
if name of theProcess is "Google Chrome" then
say "Chrome woo hoo"
say (count windows as string)
else
say name of theProcess as string
say (count windows as string)
tell theProcess
repeat with theWindow in windows
say "found a window of"
say (name of theProcess) as string
tell theWindow
click button 2
end tell
end repeat
end tell
end if
end if
end if
end repeat
end tell
I'm on Mac OS X 10.7.5, using automator 2.2.4 to write/run this applescript
You have to tell the process to count windows. After all it's the process that knows about its windows, not system events.
You have told the process to say its name e.g. "say name of theProcess as string" however you only use "say (count windows as string)"... no process is tied to that. Try "count windows of theProcess". Basically you have lines where sometimes you tell the process, other times you don't, and other times where you tell the process even though you've already told the process, so you do it twice. That's where you have "say (name of theProcess) as string" but that code is inside a "tell theProcess" block so it's already being told to theProcess.
Really you need to go through your code and be more precise. A tip... if you want to click a button in a window then the window must be frontmost on the screen otherwise you can't click it. Another tip... "name" is already a string so you don't need to coerce that to a string.
By the way, I agree with Michael Dautermann's comment to your post... there will be processes where you won't get access. But you'll find that out as you progress.
Here's how I would write your code. Basically I would get all of the variables at the beginning using a "tell theProcess" block. Then I can do stuff with those variables. I hope that helps. Notice that I only made the process frontmost which means if it has multiple windows open it will only click a button on the front window. You'll have to add code to make each window come to the front before you can click its button. Good luck.
tell application "System Events"
repeat with theProcess in processes
if not background only of theProcess then
tell theProcess
set processName to name
set theWindows to windows
end tell
set windowsCount to count of theWindows
if processName is "Google Chrome" then
say "Chrome woo hoo"
say windowsCount as text
else if processName is not "Finder" then
say processName
say windowsCount as text
if windowsCount is greater than 0 then
repeat with theWindow in theWindows
say "found a window of " & processName
tell theProcess
set frontmost to true
tell theWindow
click button 2
end tell
end tell
end repeat
end if
end if
end if
end repeat
end tell
I create a list of all open windows of visible applications on Mavericks like this:
tell application "System Events"
set this_info to {}
repeat with theProcess in (application processes where visible is true)
set this_info to this_info & (value of (first attribute whose name is "AXWindows") of theProcess)
end repeat
this_info -- display list in results window of AppleScript Editor
end tell
You need to allow any app using this to access the interface under Accessibility.
How would I quit all running user applications using Applescript?
It's okay... I think I found my answer:
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
After some googling, I found a better approach:
It uses background only to build the initial app list, rather than
visible is true. The difference is that the other scripts will fail
to quit an app that's been hidden with ⌘H.
It provides an exclusions
list so that, for example, you can prevent your script editor from
quitting each time you test the script.
Adapted from a thread on MacScripter.
-- get list of open apps
tell application "System Events"
set allApps to displayed name of (every process whose background only is false) as list
end tell
-- leave some apps open
set exclusions to {"AppleScript Editor", "Automator", "Finder", "LaunchBar"}
-- quit each app
repeat with thisApp in allApps
set thisApp to thisApp as text
if thisApp is not in exclusions then
tell application thisApp to quit
end if
end repeat
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
tell application "System Events" to set quitapps to name of every application process whose visible is true and name is not "Finder"
repeat with closeall in quitapps
quit application closeall
end repeat