Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 1883 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted (edited)

Hi,

 

I know nothing about Java or Groovy etc!

 

I want to deploy my solution and take advantage of dual screen. So I need to have information, if a 2nd screen is installed, is it to the left or right of the main screen.

 

I have found many script exemples, but every time I copy them in the ScriptMaster file and run them, I get a compilation error.

 

So if you want to help, please just don't say, use this command, or x,y,z... I would need to full script from A to Z, as I know nothing how to write a Groovy script, debug or else !

 

Thank you for your help.

 

JF

Edited by JF Fortier
Posted

For starters, why are you trying to do this with Groovy? And exactly what are you trying to do. You mention 2 screens, but not what you are trying to do. We need more details to help guide you.

Also, while we can help guide you, the main purpose of the forum is not to build it for you, it's to help guide you and explain things you don't understand.

Posted

I appreciate your help! The best way to learn is by searching and finding it when someone point you in the right direction. But sometimes people say use the Groovy function get(monitor.xyz){};HelloWorld,zulu... as it may be useful for someone that already knows Groovy, this is not helping me to get a full function that works!

 

I'm trying to achieve a plugin that will return the number of monitors 1 or 2, is the 2nd monitor located to the right or left and maybe the resolution (for future use) for now I don't need it.

 

I want to build my start-up script so that a user with 2 monitors will have 2 windows open.

We use an integration of SeedCode Calender in our solution and I want to have the calendar open full screen on the 2nd monitor and always stay open in that one, and the rest of the solution is within the main monitor, so ;

 

If (PlugIn.results = 2 monitor)

   New Window ( x,y,z. Top:0 (if Plugin.results = MonitorLeft ; -300; get(WindowDesktopWidth)  +300)

   // the new windows will then be in the 2nd monitor

  Adjust Window [Maximize]

 

Else

...

End

 

Unless you have a way of doing this native in FM... as of today, I haven't found it.

 

Thanks

Posted

Try this. We may need to modify this a bit if you have someone running on Windows 7. The command may be a little different.

One thing I, personally, don't like about this approach is that is uses the clipboard. Other options to make this work:

  • write the result to a file, instead of the clipboard, and import the file. Read the data that way.
  • use the BaseElements plugin, or your preferred plugin, to execute a system command. This way you can save the result directly to a variable.

Anyway, hopefully this gets you moving in the right direction.

MonitorInfoTest.fmp12

Posted

Some of the things you mention like

Get(WindowDesktopWidth)

and Adjust Window [Maximize]

ARE already fileMaker and I am not sure how you expect Groovy to control the FileMaker environment, and particularly not the windows.

 

Posted

@Josh Ormond The command line is not working, it's telling me that I have only one monitor connected. I played around that command line tool, but I only get one monitor, one set of resolution ?!? I have tried other way, I might investigate that path and find another command line tool, but if not Win standard, I will have the install that tool in every PC... not the best practice in deploying a solution.

 

@john renfrew The Groovy part is to set up a ScriptMaster plugin that will return the information into a variable and with that info I will script conditions to do what I need. So if I have 2 monitors, the solution will open the second window. If the 2nd monitor is L or R I will get the current FM function to send the new window in the right location.

 

I once found a Groovy code that was supposed to do that (didn't save the URL !) but I recall copy/past in the demo file of scriptmaster but the script was not working, error running/compiling...

 

Thanks,

 

Posted

What happens if you open cmd and run the command manually? It's also possible there is some odd character or string that I didn't account for, because I didn't run into it.

Posted (edited)

The issue is what you get back from Groovy and how to interpret it

this is my setup

I can get that there are two displays ( an array with two values at 0 and 1 )

I can get the starting position and size, but the values returned in this case show both of them as 2560*1440

BUT with a monitor2 on the right I get

[0] == java.awt.Rectangle[x=2560,y=0,width=2560,height=1440]
[1] == java.awt.Rectangle[x=-0,y=0,width=2560,height=1440]

and with the monitor 2 dragged to the left I get

[0] == java.awt.Rectangle[x=-2560,y=0,width=2560,height=1440]
[1] == java.awt.Rectangle[x=-0,y=0,width=2560,height=1440]

you can get these values by using this code and changing the gs[0] for gs[1] to see the differences

import java.awt.GraphicsConfiguration
import java.awt.GraphicsEnvironment


ge = GraphicsEnvironment.getLocalGraphicsEnvironment()
gs = ge.getScreenDevices()
gd = gs[0]
gc = gd.getConfigurations()
return gc[0].getBounds()

if you use Toolkit and getScreenSize the docs say

getScreenSize

DimensiongetScreenSizeHeadlessException
 GraphicsConfiguration  GraphicsDevice

import java.awt.Toolkit

screenSize = Toolkit.getDefaultToolkit().getScreenSize()
return screenSize

 

however as I pointed out this will not help as both displays report the same size so I have no way of inferring which one is positioned where

 

125545159_ScreenShot2019-10-08at16_23_30.thumb.png.fa3f0db734cbc9b73550641fc68eb22c.png

 

Edited by john renfrew
  • Thanks 1
Posted

@john renfrew 

This is going in the right direction! In your case the retina display, I may be wrong put it's not something like @2x in the Apple docs? so the pixel is 1/2 of the resolution so your 5120 x 2880 return in fact 2560x1440

My Monitor #1 is 1920 x 1080

Monitor #2 (left) is 1680 x 1050

 

The result is

gs[0] = java.awt.Rectangle[x=0,y=0,width=1920,height=1080]

gs[1] = java.awt.Rectangle[x=-1680,y=0,width=1680,height=1050]

 

So monitor 1 sets at 0,0 1920x1080 and monitor 2 (left) is the screen resolution 1680 x 1050, since it's on the left side is -1680,0

On the right I get gs[1] = java.awt.Rectangle[x=1920,y=0,width=1680,height=1050]

 

So for me, this code is working, if I try with gs[2] and I don't have a 3rd monitor I get Groovy Script failed:2

 

I added a variable to set the monitor number "ScreenNo" and the Groovy now look like this

import java.awt.GraphicsConfiguration
import java.awt.GraphicsEnvironment

int x = Integer.parseInt(ScreenNo);
ge = GraphicsEnvironment.getLocalGraphicsEnvironment()
gs = ge.getScreenDevices()
gd = gs[x]
gc = gd.getConfigurations()
return gc[0].getBounds()

and after some cleaning, the code requires is

import java.awt.GraphicsEnvironment

int x = Integer.parseInt(ScreenNo);

return GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[x].getConfigurations()[0].getBounds()

I can now run a script with a loop that will go from 0 until the plugin return ERROR and get into variables the info and with a custom function get this the data out of this result "java.awt.Rectangle[x=0,y=0,width=1920,height=1080]" 

 

Thanks John, you just made my day :)

 

 

 

Posted

I found the code that I had that only return the coordinates and screen size. I just add the "import" section, that is what was missing from my previous attempt.

 

import java.awt.GraphicsDevice;

import java.awt.GraphicsEnvironment;

import java.awt.Rectangle;

 

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

String boundsString = "";

for (GraphicsDevice gd : ge.getScreenDevices()) {

    Rectangle bounds = gd.getDefaultConfiguration().getBounds();

    boundsString += bounds.x.intValue() + " " + bounds.y.intValue() + " " + bounds.width.intValue() + " " + bounds.height.intValue() + "\n"

}

return boundsString;

 

and it return plain data

0 0 1920 1080
-1680 0 1680 1050

 

Maybe this will help someone else in the future, you have 2 options, you just have to extract the data you want from the result.

 

JF

  • Like 1
Posted

See, we all learned something...

To make things more Groovy, you don't need any semicolons at the end of lines, and in most cases you don't need the class assignments at the start for line, Groovy auto typecasts as it knows what the returned object is...

  • Like 1

This topic is 1883 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.