cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
shampton82
Level VII

Have a new window appear next to current mouse location

Is it possible through JSL to get the location of the mouse and then have a new window open to the right of it?  It seems straight forward enough but looking through the scripting help I couldn't figure it out.  thanks for any pointers!

Steve

7 REPLIES 7
txnelson
Super User

Re: Have a new window appear next to current mouse location

The only way that I believe that one can get the mouse position from anywhere on the screen, would be through either the JMP extension into R or Python.  Once the mouse position is returned, then JSL can create the New Window(), and then Move Window() to the desired position. 

Jim
jthi
Super User

Re: Have a new window appear next to current mouse location

If you are using windows you could use powershell. Here is one example (might be good idea to return also number of display and not just coordinates):

Names Default To Here(1);

powershell_variables = Eval Insert("\[Add-Type -AssemblyName System.Windows.Forms
$X = [System.Windows.Forms.Cursor]::Position.X
$Y = [System.Windows.Forms.Cursor]::Position.Y
Write-Output "X: $X | Y: $Y"]\", "¤");

//fix quotes and cleanup
quote="\!"";
escapedquote = "\!\\!"";	
Substitute Into(powershell_variables, quote, escapedquote);

r = Trim Whitespace(Run Program(
	Executable( "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" ),
	Options({powershell_variables}),
	Read Function("text")
));

I have usually managed these by opening new windows on top of current window() and then calculated the location based on that. 

-Jarmo
shampton82
Level VII

Re: Have a new window appear next to current mouse location

thanks for the suggested code.  I'm not familiar with powershell so I just grabbed your code and ran it and got this in the log:

 

"Add-Type : Cannot add type. Definition of new types is not supported in this language mode.
At line:1 char:1
+ Add-Type -AssemblyName System.Windows.Forms
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [Add-Type], PSNotSupportedException
+ FullyQualifiedErrorId : CannotDefineNewType,Microsoft.PowerShell.Commands.AddTypeCommand

Unable to find type [System.Windows.Forms.Cursor].
At line:2 char:6
+ $X = [System.Windows.Forms.Cursor]::Position.X
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Windows.Forms.Cursor:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound

Unable to find type [System.Windows.Forms.Cursor].
At line:3 char:6
+ $Y = [System.Windows.Forms.Cursor]::Position.Y
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Windows.Forms.Cursor:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound

X: | Y:"

 

I didn't see anything returned that I could use for the position of the mouse.  Am I missing something or do I need to do something to set up powershell?  I'm using two monitors and running the script on my primary one.

 

Steve

txnelson
Super User

Re: Have a new window appear next to current mouse location

What is your version of JMP?

Are you running Windows 10?

 

Jim
shampton82
Level VII

Re: Have a new window appear next to current mouse location

JMP Pro 16.0, Windows 10 Enterprise version 10.0.19044

jthi
Super User

Re: Have a new window appear next to current mouse location

I'm not too familiar with powershell either, I only use it when I have to. You could try running that command

 

Add-Type -AssemblyName System.Windows.Forms
$X = [System.Windows.Forms.Cursor]::Position.X
$Y = [System.Windows.Forms.Cursor]::Position.Y
Write-Output "X: $X | Y: $Y"

directly in powershell and see if you get the same error. This is when I run powershell through commandline:

 

jthi_0-1646288103448.png

If I run the command by windows searching for powershell it seems to return similar error:

jthi_1-1646288388895.png

but if I run it again after the errors, it seems to return either string without coordinates or coordinates as it should.

-Jarmo
shampton82
Level VII

Re: Have a new window appear next to current mouse location

I could get it to work through Windows Powershell ICE but not Windows Powershell, don't know what that means but just throwing it out there in case anyone else does!