Wednesday, December 13, 2017

#1 2015-09-13 12:42:27 pm

Joseph25b
Member
Registered: 2015-08-31
Posts: 31

Moving a window with ASOC

Hello,

I'm a full newbie in ASOC and Xcode and I'm stuck with this "problem":
I have an application's window (bound as "mainWindow" outlet in the appDelegate) of which I want to get its origin coordinates.
Let's say X0, Y0
Then I have a modal window (outlet = progressWindow) which contains a progress bar and a prompt.
I want that this  progressWindow will display always at a fixed position relative to my mainWindow when called to display.
Let's say (X1 = X0 + a) and (Y1 = Y0 + b)
First: How to retrieve X0 and Y0?
Second: how to move my "progressWindow" to (X1, Y1) requested position?

I found an example in ObjctiveC but I'm unable to translate in good ASOC, always get an error hmm

Thank you in advance.
BTW, many thanks to the numerous posters on Macscripter from whom I took tools and tips to built my modest application.

Joseph


Joseph from France
MacPro 10.7.5 - XCode 4.6.3

Offline

 

#2 2015-09-13 06:35:04 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Moving a window with ASOC

You find the windows coordinates by asking for its frame() -- this returns an NSRect, which gives you it's origin (bottom-left x, y) and size (width, height). To move a window you can use one of several frame-related methods: setFrame:, setFrameOrigin:, setFrameDisplay: or setFrame:display:animate:.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#3 2015-09-13 06:57:07 pm

Joseph25b
Member
Registered: 2015-08-31
Posts: 31

Re: Moving a window with ASOC

Shane Stanley wrote:

You find the windows coordinates by asking for its frame() -- this returns an NSRect, which gives you it's origin (bottom-left x, y) and size (width, height). To move a window you can use one of several frame-related methods: setFrame:, setFrameOrigin:, setFrameDisplay: or setFrame:display:animate:.


Thank you Shane, I'm about to dig into the second part (moving window).
I just found a method, not sure it's very elegant but doing the job, about retrieving X0 and Y0.

Applescript:


on giveMyFrame()-- the display dialog is for example
set dimsWin to mainWindow's frame as list
set dims2Win to (item 1 of dimsWin) as record
set XY to (origin of dims2Win as list)
set X0 to item 1 of XY as text
set Y0 to item 2 of XY as text
display dialog X0 & " - " & Y0
end giveMyFrame

Regards,
Joseph


Joseph from France
MacPro 10.7.5 - XCode 4.6.3

Offline

 

#4 2015-09-13 07:07:09 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Moving a window with ASOC

If you use:

Applescript:

set dimsWin to mainWindow's frame()

You'll get a record something like this:

Applescript:

{origin:{x:100.0, y:100.0}, |size|:{width:200.0, height:100.0}}

So you can then do:

Applescript:

set XO to x of origin of dimsWin
set YO to y of origin of dimswin


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#5 2015-09-14 01:39:09 am

Joseph25b
Member
Registered: 2015-08-31
Posts: 31

Re: Moving a window with ASOC

Hello Shane,

So you can then do:

Applescript:

set XO to x of origin of dimsWin
set YO to y of origin of dimswin


Obviously smarter than my awkward function! ;-)

Thank you for it: I always considered that "style" in writing code is almost as important as efficiency.


Regards
Joseph


Joseph from France
MacPro 10.7.5 - XCode 4.6.3

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)