Mouse click on Flash element in AppleScript - applescript

At my university we're using a very shitty Flash video player for the recorded lectures. It's not possible to download the recordings, so my solution is to record the lectures with quicktime using an applescript script(Completely legal by the way). In this way, I can choose my own playback speed and it's much easier to pause/play the video. You can see an example here:
http://vc.au.dk/videos/video/9115/
The problem is that my script need to click on a Flash element in the video player to switch to another presentation layout (for instance a zoom in on the black board). You can see an example here: https://i.imgur.com/Uwqwopg.png.
I have tried something like the following:
tell application "System Events"
click at {123,456}
end tell
But this does not do the click.
It just says:
"group 5 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "LifeSize UVC Video Center - Computability & Logic F2020 - 06 March 2020" of application process "Safari" of application "System Events""
Do you have any suggestion to how I can click this particular button via applescript?
If you need more information, please let me know!
Thank you very much!

If clicking on a particular point is how you want to go about this, use cliclick. You can trigger it using AppleScript's do shell script
You'll have to use the full path to cliclick to get it to work (like /usr/local/bin/cliclick)
So, the do shell script cliclick version of your example would be:
do shell script "/usr/local/bin/cliclick c:123,456"
https://www.bluem.net/en/projects/cliclick/

Related

Applescript- UI Element Group changes when I scroll around page

I'd like to preface that I am very new to Applescript and UI scripting. I am working inside a proprietary CMS and wish to build a script to open a file search box, paste in the filename, select it, and click Finish. I have been successful scripting the UI hierarchy, but have noticed that if I scroll around the page then the Group number changes which breaks my script.
For example, this snip of script works, but if I scroll around the page then the Group number changes from 47 to 48. The entire script is performing several copy/paste functions and this Group change sometimes occurs mid-run, so I can't "set it and forget it".
tell application "System Events
perform action "AXShowMenu" of text field 1 of group 1 of group 1 of group 1 of group 47 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "Strapi - Content Manager" of application process "Safari"
end tell
I'd like to target this text field via an UI attribute (and hopefully ignore Group number or possibly condense the UI string), but am not sure exactly what to use. Several fields such as Title and Description are blank. I am including a screenshot of UI Browser for this element. I'm also open to incorporating JavaScript but have zero knowledge so there'd be an obvious learning curve there. I appreciate any and all help!

Change video player position with AppleScript?

I have got a problem and I really don’t know how to solve it: I would like to change the player position of this / this video while it is opened in the background (so that another tab or application can be active at the same time). I can’t find anything helpful in the sourcecode and GUI scripting is not an option.
Thank you in advance!
EDIT: I came up with an idea: I changed the user agent to iOS 10 (iPhone) although I’m not sure if this makes the whole thing easier.
You can do this with AppleScript and JavaScript if the video player is using the HTML5 video tag. Like you said, changing your user agent to an iOS device increases your chances of being served this instead of a flash player.
First, you need to search for the correct window by URL. Then, the script will run some Javascript in the window to update the time of the video. Change the properties to fit your usage. If the page has multiple video tags, you can change the [0] to which one by order on the DOM, or target by ID instead.
property checkURL : "vimeo.com"
property changeTime : 90
try
tell application "Safari"
set theTab to first tab of window 1 whose URL contains checkURL
do JavaScript "document.getElementsByTagName('video')[0].currentTime = " & changeTime in theTab
end tell
on error
display dialog "That site is not loaded"
end try

Can AppleScript read mouse position / action in one application and replicate it in another application?

I've been searching for a mouse broadcaster for Mac for a while and it seems there are no solutions for doing this, so I must look for alternative solutions now. I'm wondering if AppleScript is capable of performing such a task. Basically, what I would like to do is read mouse position and action when performed in one application for as long as the script is active, and broadcast/replicate it in one or more other applications. Is AppleScript capable of this?
Just to clarify, I'd need to simulate mouse movement in the other applications... for example, if I opened up several instances of a drawing program, assuming that the program had the same resolution, anything I drew in the main program, would replicate on the other programs.
Really applescript cannot do what you need. It's not made for that. Applescript is made to run the commands in an application's applescript dictionary. I assume that the dictionary of the applications you want to control give you no way to read and control the mouse.
You do have an applescript alternative though. I have made a command line tool to read the mouse position and also to move the mouse. So theoretically you can do what you want with applescript and my tool. I do not believe you will get the results you expect though. Anyway you can try. Here's a link to the web page for my tool. I hope it helps.
Get it here.
Your basic approach could be 1) activate the application you want to read the mouse position, 2) run my tool in a repeat loop and record the mouse positions, 3) activate the second application that you want to duplicate the mouse movements, 4) use a repeat loop with my tool to make the mouse move according to how you recorded it.

How to create a basic chatbot/auto responder based on browser contents? (Applescript, or other recommendations?)

I am a (very) beginner programmer and I am wondering if it would be feasible to write a very simple chat room bot which is fairly dependent of what kind of chat room is being used.
The scenario is that a friend of mine has a basic chat room set up (https://blueimp.net/ajax/) just for a few buddies to use, but I want to make a "bot" account that exists only on the client machine (mine). So, it would continually check the browser (without reloading the page) for a particular string and then respond if it detects it. Just as an example, maybe they would type !bot song and it would return with a song recommendation.
I was thinking Applescript could be an easy way to do this. Can anyone possibly help get me started? Like I said, I'm a beginner so please keep that in mind. Trying to use this as a learning experience, and I learn best by trying to come up with a solution to a particular scenario rather than by books or tutorials.
Essentially, the flow would be something like:
Check webpage for string every 2 seconds (it's Ajax-based, no need to refresh... just check the browser window itself)
If string is found, reply in the first text field with response + enter
I know this isn't the most efficient way to make a chat bot, I'm just trying to use this scenario to help me understand how applications interact with each other locally. :)
I hope I'm not breaking some unwritten rule of StackOverflow by giving you this code, but you could try out this AppleScript code and see how it works (assuming the whole browser window is just the chat box, change this as needed):
repeat
tell application "Safari" --or whatever browser you use
set the message to ""
repeat until the message contains "something" --replace 'something' with the string you want to search for
set the message to (the text of document 1) as string --all text on the page
end repeat
end tell
tell application "System Events"
tell process "Safari"
select text box 1 of document 1 --assuming the chat box is the only text box on the page; if not, determine which number the chat box is.
--Text boxes are numbered starting at 1 and ending at the last text box. The 'search' goes from left to right, once the right edge of the window is reached, the search goes down until it reaches the next box.
--Once you determine the text box's number, change the 'text box 1' to 'text box [number]', where [number] is the text box's number.
keystroke "response" --replace 'respose' with the reply you want to send back
end tell
end tell
delay 2 --wait 2 seconds so the script doesn't spam the chat box
end repeat
If this doesn't work for some reason and/or you have any questions, just ask. :)

How do I move first responder with applescript?

I want to address the following annoyance with iTunes: After I have searched for a track (by pressing cmd+opt+f to move to the search field) I want to be able to play the first track in the songs list. Ideally I would like cmd+enter to start playing the first track in the song list and also move the focus to the song list. For example I enter 'Highway 61' in the search box, press cmd+enter and 'Like a Rolling Stone' starts playing.
My initial idea is for an applescript that moves the focus from the search field to the song list, selects the first song and plays it.
Here's what I have:
tell application "iTunes"
set first responder of (window 1) to outline "songs"
end tell
When I try to run this script Applescript Editor throws a syntax error "Expected class name found identifier" and highlights responder. This script follows the same form as many of the applescripts I've found on the web. What am I doing wrong?
Aside/rant: Applescript is the most frustrating and confusing technology I've ever had the stupidity to inflict upon myself. I hate it. I hate it. I hate it. I hate it.
Applescript's syntax is idiosyncratic, but it's not bad in the sense that you have a uniform scripting language for GUI. This was (and still is) something amazing. The strange sytanx is also not that strange once you go through Apple's language definition which can be found here.
That said, you need to open the AppleScript Dictionary of each app to see what kind of nouns and verbs are defined.
Think of an app as a library of classes and methods from the point of view of the AppleScript. Of course you can't call a method which is not defined in a library, right?
Launch AppleScript Editor, go File→Open Dictionary, and choose iTunes. You soon find that there's no such noun as first responder is defined.
The point is, the app usually only exposes its internal object structure, not every element of the UI. But usually that's enough.
If what you want to do cannot be done using the proper Applescript interface an app exposes, as a last resort, you can directly manipulate the UI elements, using a helper app called "System Events".
So, go File→Open Dictionary again, and this time choose "System Events", and check the content of "Processes Suite." It allows you to manipulate the UI. For example, to get the list of all UI elements, use
tell application "System Events"
tell application process "iTunes"
get UI elements of window 1
end tell
end tell
Have fun! Applescript looked horrible to me for a while, but it's not a bad thing once I learned I need to always refer to the dictionary.
Mac OS X Automation is a great source of tutorials.
If I understand correctly, you don't need an AppleScript to do that. Just press the Tab key to move the focus between elements. In my case, for example, pressing Tab moves the focus from the search box to the left-side selection bar then to the main list of songs then back to the search box again.
EDIT Addressing your further refinement of the question: you can get from searching to playing with two key strokes - TAB to move the focus out of the search box to the song list, then SPACE to play the first track in the selection. You can also use the arrow keys to pick a different selection.
Just for fun, though, here's one way you could do the whole sequence in AppleScript:
tell application "iTunes"
play first item of (search first library playlist for "Highway 61")
end tell
AFAIK, iTunes doesn't implement the command set first responder of. Applescript studio implements such command.

Resources