AppleScript for AirPlay Button in the new TV app - user-interface

Can anybody figure out how to click the AirPlay Display pop up button in the new TV app (found in MacOS Catalina) using AppleScript? I've tried a zillion different ways, and still get the result "missing value."
As far as I know this code should work:
tell application "System Events"
tell application process "TV"
tell window 1
click ((button whose description is "airplay") of pop up button 1)
end tell
end tell
end tell
Here is a picture of the Accessibility Inspector for that pop up button:
UPDATE: Apparently the new TV app in Catalina is not fully scriptable. AppleScript support for AirPlay Displays does not exist (neither directly nor through GUI scripting). Hopefully, Apple will add support in the future...

Related

How to get current playing song on mac by command line tools?

I can only find some applescripts on Google with specific music app(like itunes, spotify, etc) to get current playing song.
But now I'm using Netease Music which not supporting to be controled by applescript, I wonder if there is any universal way to get current playing song info via mac media center?
Applescript and other command line tools both ok.
I made a cli tool that lets you read properties from the private MediaRemote framework.
https://github.com/kirtan-shah/nowplaying-cli
Since it uses private APIs, it may break with future macOS updates but is currently working on Ventura 13.1.
Here is an example that will retrieve the song name:
This following AppleScript code uses UI scripting to retrieve the currently playing media.
tell application "System Events" to tell process "Control Center"
click menu bar item "Control Center" of menu bar 1
set currentlyPlaying to value of static text 3 of window "Control Center"
key code 53 -- press 'esc' key
end tell
activate
display dialog currentlyPlaying with title "Currently Playing" buttons ¬
{"OK"} default button 1 giving up after 3

How to find a specific tab while multiple Google Chrome windows are open in AppleScript

to clickClassName(theClassName, elementnum)
tell application "Google Chrome"
set youtubeTab to (the first tab of window 2 whose URL contains "youtube")
end tell
tell application "Google Chrome"
execute youtubeTab javascript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();"
end tell
end clickClassName
clickClassName("ytp-play-button ytp-button", 0)
I have two windows open on my MacBook. One on the MacBook itself another one on the external display. I would like to play/pause YouTube videos playing on the external display while taking notes on my MacBook. Above script works only if the windows on the MacBook is activated because it is specifically pointing to the other window via window 2.
I think I need to find all windows and somehow use the repeat operator so that I can play/pause the video regardless of which window is activated. But I am not sure how to approach.
Any help is appreciated!
PS. I have added this script as a Service and assigned a specific key combination. So when I am taking notes on my MacBook I can quickly play/pause the video.
The following example AppleScript code will click the Play/Pause button on a YouTube video in any (every) tab of Google Chrome whose URL contains youtube:
tell application "Google Chrome"
set YouTubeTabs to a reference to ¬
(tabs of windows whose URL contains "youtube")
repeat with aTab in YouTubeTabs
tell aTab to ¬
execute javascript ¬
"document.getElementsByClassName('ytp-play-button ytp-button')[0].click();"
end repeat
end tell
Assuming you only have one tab in Google Chrome that has a YouTube video to play/pause, this will certainly do it for you.

Automated FaceTime audio call using AppleScript

I tried to do automated facetime audio call when some event are observed in my python application. I used the code from here https://apple.stackexchange.com/questions/189774/make-a-facetime-call-using-applescript and changed the facetime:// to facetime-audio://
do shell script "open facetime-audio://my_number"
tell application "System Events" to tell process "FaceTime"
set frontmost to true
tell window 1
repeat while not (button "Call" exists)
delay 1
end repeat
click button "Call"
end tell
end tell
For the facetime video call, it worked perfectly, but for the audio call, my Mac still asked me to manually click the Call button before making any call. How do I solve this? My Mac version is 10.15.6.
Somewhere along the way Apple moved the Call button to Notification Center
If you change "FaceTime" to "Notification Center" in your AppleScript code, it should work.
Testing under macOS High Sierra and macOS Catalina this worked for me. Note however, in the Preferences of FactTime an Apple ID account needs to be enabled and already signed in for this to work properly. This is normally the case once you've signed in once and remains so between subsequent opening/closing of FaceTime unless you've explicitly signed out.

How to check the checkbox of Adobe Installer with the Aplescript?

am trying to Install Adobe Flash Player, I want to check the check box and need to click on Install button, Whem am trying to get the entire contents of window thru UIElementInspector, am unable to get the contents of checkbox and Install buttons..
I just tried myself with the below script to click the checkbox, but did not succeed, error saying unable to get the checkbox.. Pls suggest how to check..
tell application "System Events"
tell process "Adobe Flash Player Install Manager"
set frontmost to true
click the checkbox "I have read and agree to the terms of the Flash Player License Agreement" of window "Adobe Flash Player 11.5 Installer."
end tell
end tell
Pls check the below link to view the image of the Adobe Flash Player Installer.
https://docs.google.com/document/d/1yzyBTrvi94QxjlEAlcbudOBpXiTGPEI2LA3D1iEo8Gw/ edit
Download this S/w:
http://pfiddlesoft.com/uibrowser/downloads/UIBrowser222.dmg
Install it.
You can simply use this tool to read the name of checkboxes and all.
For ex: if you attach a application which is having a window and a checkbox within it you can check that checkbox simply by following script:
tell aplication "system events"
click checkbox 1 of window 1
end tell
Just remember to keep the window on front most amongst other windows.
You can attach your process by clicking target pop-up button present in the UI Browser app.
Then click on Switch to screen reader option.
Now you can just see the names of the buttons, controls, checkbo

How can I automate application installations that have dialog boxes that need input?

I am trying to install the downloaded application programatically, hence I am using apple script for the same since am working on Mac.
Here I've downloaded the Adobe AIR Installer app from adobe site which is in downloads folder and am trying to install the same with the below applescript code. Here when the Adobe AIR setup dialog box opens, I need to click on "I Agree" button to install the app.
With the below code am not able to click on the "I Agree" button, even i dont have Xcode Accessibility Inspecter do inspect the element. Pls guide me the script to handle the "I agree" button.
try
tell application "Finder"
activate
open application file "Adobe AIR Installer.app" of folder "Applications" of startup disk
set this_image to open this_file
delay 5
tell application "System Events"
click button "I Agree" of window "Adobe AIR Setup"
end tell
end tell
end try
You could try GUI scripting the commands with delays in-between clicks, but it's a little bit of work. Since the Adobe installer doesn't support clicking from applescript, you will need to download ExtraSuite and follow along with this previous MacScripter post.
To get pixel coordinates, start up the installer without AppleScript and type '⌘ + shift + 4' to get the crosshairs with pixel location (usually used for taking screenshots). Write down the coordinates for the first button and then hit 'esc' and move to the next button.
This is a pretty painful way to get the job done but there aren't many other alternatives that I know of.
It looks like the Adobe installers don't use Cocoa and aren't scriptable. You might have better luck with Sikuli. It's based on matching bitmaps and doesn't depend on any underlying framework.

Resources