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
Related
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/
I would like to know if it's possible to simulate the process: Right click on an image -> Click on "Save image as.." on the popup menu -> save the image in local.
I tried CaptureBitmap() function, but the result is just a screenshot taken by QTP, not the same image file obtained as the procedure above.
Are there other ways? Many thanks in advance.
Allen
I suppose it depends what you want to do. If you want to compare the bitmap then the CaptureBitmap options should work. If you want to compare the path to the image you can use Image("x").GetROProperty("src").
If you really want to save the src image file then unfortunately QTP doesn't supply a way to interact with the browser's context menu. You can try to use some third-party mechanism to download the image from the src URL (e.g. wget).
Edit: I just had another thought, I'm not at work so I can't verify that it will work but I'm pretty sure it will.
First cause the context menu to appear, in order to do this you have to change the replay mode to device and run a RightClick operation.
replayType = Setting.WebPackage("ReplayType") ' Store old replay mode
Setting.WebPackage("ReplayType") = 2 ' change to device replay mode
Browser("b").Page("p").Image("I").RightClick
Setting.WebPackage("ReplayType") = replayType ' Revert to old mode
Then send the letter v to the browser which will select the Save menu item (on both IE and Firefox) by using the device replay object
Set deviceReplay = CreateObject( “Mercury.DeviceReplay” )
deviceReplay.SendString "v"
Now interact with the save dialog as a usual Win32 control.
Moral: Never underestimate what QTP will let you do if you try hard enough
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. :)
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.
I'm looking into windows management on OS X (trying to achieve something like WinSplit Revolution), and I need to use applescript to pull out the maximum size of a window on a given monitor. Currently I've found:
tell application "Safari"
set screen_width to (do JavaScript "screen.availWidth" in document 1)
set screen_height to (do JavaScript "screen.availHeight" in document 1)
end tell
This works for the main monitor on a multiple monitor setup, but doesn't provide at all for secondary monitors. I've also read into the method detailed here, and this obviously doesn't work for multiple displays in an efficient manner. Is there an effective way to get the maximum window size of multiple displays with applescript?
There have been many attempts to get monitor dimensions by reading system plist files. See http://macscripter.net/viewtopic.php?id=15425
If you have access to AppleScript studio (ASS) terms, you can make method calls into NSScreen to get all the monitors then ask them for their sizes. The easiest way to use ASS terms in a plain AppleScript is to compile an empty ASS application in Xcode. In this example, I've created a simple ASS app name ASSAccess which gives me access to ASS terms:
tell application "ASSAccess"
-- The first item in this list will be your main monitor
set screensArray to call method "screens" of class "NSScreen"
set Displays to {}
if {} is not screensArray then
repeat with displayNo from 1 to (count screensArray)
-- call visibleFrame instead to take into account the Dock and menubar
set dims to call method "frame" of (item displayNo of screensArray)
copy dims to end of Displays
end repeat
end if
end tell
Now, the issue I run into with these dimensions is the coordinate system. NSScreen's frame method gives you a rectangle with the origin in the LOWER left hand corner of the main monitor. Then, any secondary screens are given relative to that origin. If you are trying to determine if a window is within these bounds, window position is giving within a coordinate system with the origin at the UPPER left hand corner. This is a whole mess of conversion that I haven't figure out yet.