How to take a partial screen capture using Ruby? - ruby

I need to run a ruby client that wakes up every 10 minutes, takes a screen-shot (ss) of a users screen, crops part of the (ss) out and use's OCR to check for a matching word....its basically a program to make sure remote employees are actually working by checking that they have a specific application open & the case numbers shown change.
Not sure where to even start when it comes to taking a screen-shot and cropping it, has anyone done any kind of screen capture work using Ruby?
The app will run on OSX using Ruby 1.9
Thanks!

On OS X you can use the screencapture command in the terminal to capture the screen, so capturing the screen from Ruby shouldn't be more than
def screen_capture(path)
`screencapture #{path}`
end

Related

Gosu::Song in Ruby only playing first note

I'm trying to write a simple game in Ruby (ver 2.2.6) on Windows. I installed the Gosu gem to handle the audio, and I have a soundtrack file that I would like to play:
#soundtrack = Gosu::Song.new("theme.ogg")
I cannot use Sample, because I need to be able to pause.
def play_soundtrack
#soundtrack.play(looping = true)
end
def pause_soundtrack
print "Paused "
#soundtrack.pause
end
Running this only plays the first note of the theme, and then no sound will play. Gosu::Sample still works as it should, so I'm not sure what could be wrong with my use of Gosu::Song.
This is not possible with Gosu right now, Song#play does not work without a window. Because Gosu does not use a background thread to play audio, there is an internal Song::update() method that needs to be called periodically to keep the song playing. Gosu::Window#show does this once per tick. There is no way to directly call this method from Ruby. The only workaround is to show a tiny window while audio is playing.
I've opened a GitHub issue because this should either be documented or fixed.

How to detect which screen is the OSVR headset?

I have an WPF+SharpDX Windows application that displays to the OSVR HDK via a fullscreen window on the screen that is the HDK. This setup works well, but it requires users to state which screen the HDK is on.
I would like to have that automatically detected, but haven't seen anything in the API on which screen is the headset.
Currently I render in a window:
var bounds = dxgiDevice.Adapter.Outputs[_selectedOutput].Description.DesktopBounds;
form.DesktopBounds = new System.Drawing.Rectangle(
bounds.X, bounds.Y, bounds.Width, bounds.Height);
And _selectedOutputis the thing I'm looking for.
I don't support direct mode at this time and I'm using Managed-OSVR. The application will run on Windows 8/8.1/10.
It's been a while since I coded anything for OSVR, but here's from what I remember:
If you're running in extended mode, the OSVR is treated as a regular display. You can rearrange it as any other screen. The output location can be configured in the OSVR config file.
I used the following (Java) to retrieve the position and size to set up my window:
osvrContext.getRenderManagerConfig().getXPosition()
osvrContext.getRenderManagerConfig().getYPosition()
osvrContext.getDisplayParameters().getResolution(0).getWidth()
osvrContext.getDisplayParameters().getResolution(0).getHeight()
To clarify: I don't know if you can retrieve the id of the display in extended mode. From what I know, it's only defined as a position and size on the desktop.
I hope that it helps you, somewhat.

Run "Shoes::Every" in background of a Shoes::App (Ruby)

I have been working on a makeshift RPG, and the Regenerate function, is supposed to be called every 3 seconds, NO MATTER WHAT THE PLAYER's STATUS IS
For Example:
Shoes.app do
# Display on main screen
animate do
# Set para(s) to current values of health and other stats
end
every 3 do
RegenerateVitals
end
end
But at times, the user will click on buttons that will trigger functions and new windows (the base window will keep opened in the background at all times.)
Do the every function really runs behind the scenes every 3 seconds no matter what menu the player is on? Or do I need to do something else for that?
Thanks.
Yes, the specification is that every calls the block no matter what (as long as the main windows stays open). I looked up the implementation of shoes4 and that one definitely does it (using the SWT scheduler) but other implementations such as Shoes 3.1, 3.2 and green shoes should do the same.

Waiting for content loading in Appium

I read manuals, but I'm confused yet, when it's necessary to use wait method in Appium. So, what I have to implement (on Ruby):
When app starts, it shows Sign in activity. I enter log in data there and click Sign in button.
App goes to another activity. First, empty screen is shown with circular progressbar, then loaded data is shown.
I want to tap on this screen in specified place.
My code is:
textfield(1).send_key('login')
textfield(2).send_key('password')
button(1).click
Appium::TouchAction.new.tap(x: 0.5, y: 0.5).perform
In arc it works perfectly, but when it's running in tests I have a problem on step two: it seems tap is executed on empty screen, when data is not loaded yet. So, how can I tell to test that it's necessary to wait some time?
I am not familiar with ruby,
In python we use this after line of code to wait for specified time you can give 5,10,15,20 in seconds as required.
self.driver.implicitly_wait(10)

What is the flag to show the nesting of views in a Mac app?

I have just spet the last few hours trying to find the flag to use in Terminal to launch an app with the colored outlines around the various view elements to show how they are nested. I know that Matt Gemmell covered it during the Cocoa Face Off session of NSConference 2009 (at about the 13minute mark in the video). Unfortunately I can't actually read what he types and he doesn't speak the exact command. I know it has to be in the Apple docs somewhere but the search system is currently not being of any use. It looks like her just adds -showAllViews YES to the end of the command to open TextEdit but that command has no effect in 10.6.6. I have also tried every other capitalization I can think of as well as using view instead of views. Every command opens TextEdit just fine but doesn't show the colored outlines.
Use -NSShowAllDrawing and -NSShowAllDrawingColor:
/Applications/TextEdit.app/Contents/MacOS/TextEdit -NSShowAllDrawing 200 -NSShowAllDrawingColor cycle
-NSShowAllDrawing sets the delay between drawing commands (allowing you enough time to see the drawing update)
-NSShowAllDrawingColor sets the fill colour for the regions with pending drawing operations (see class methods on for NSColor for valid values, or pass it "cycle" to loop through all available colours).

Resources