Old 10-29-2020, 02:50 AM   #1
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,094
Default OSX: Request: Center Focussed Window.

Hi,

I am using Reaper on OSX, (Catalina), using 1 screen.

I would be very thankful to have a Script that just places a currently focussed window (for example the Media Explorer window) at the center of screen.

Many TIA !
__________________
Reaper - OSX (always latest version)
OSX Catalina (always latest version)
My Reaper Tips&Tricks: https://www.youtube.com/user/vanhaze2000/playlists
vanhaze is offline   Reply With Quote
Old 10-29-2020, 09:34 AM   #2
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 2,129
Default

Most of this code if from a Lua script by amagalma, so I assume it works on both MAC and Windows. When set to a global shortcut(I used Control+F11 on Win10) it seems to work OK...

Code:
function Main()
  local hwnd = reaper.JS_Window_GetForeground() 
  if hwnd and hwnd ~= reaper.GetMainHwnd() then
    local _, left, top, right, bottom = reaper.JS_Window_GetRect(hwnd)
    local pos_x, pos_y, screen_w, screen_h = reaper.my_getViewport(0, 0, 0, 0, left, top, right, bottom, true)
    local width = right - left
    local height = math.abs(bottom - top)
    left = math.floor((screen_w+pos_x)/2 - width/2)
    top = math.floor((screen_h+pos_y)/2 - height/2) 
    reaper.JS_Window_SetPosition( hwnd, left, top, width, height )
  end
end

if not reaper.APIExists('JS_Window_SetPosition') then
  reaper.MB('js_ReaScriptAPI extension is required for this script.', 'Missing API', 0)
  -- See, https://forum.cockos.com/showthread.php?t=212174
else
  Main()
end
reaper.defer(function() end)

Last edited by Edgemeal; 10-29-2020 at 01:38 PM. Reason: Updated: Removed unnecessary code
Edgemeal is offline   Reply With Quote
Old 10-29-2020, 11:47 AM   #3
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,094
Default

Many thx for helping me !
However, i dunno which lines to delete exactly, when you say: remove Return call.

__________________
Reaper - OSX (always latest version)
OSX Catalina (always latest version)
My Reaper Tips&Tricks: https://www.youtube.com/user/vanhaze2000/playlists
vanhaze is offline   Reply With Quote
Old 10-29-2020, 01:35 PM   #4
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 2,129
Default

Quote:
Originally Posted by vanhaze View Post
Many thx for helping me !
However, i dunno which lines to delete exactly, when you say: remove Return call.

Sorry for any confusion, there was a line in the code that wasn't necessary so I removed it!
Edgemeal is offline   Reply With Quote
Old 10-29-2020, 11:45 PM   #5
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,094
Default

Hi Edgemeal,

Your Script works great, thank you really much, so happy with this !
__________________
Reaper - OSX (always latest version)
OSX Catalina (always latest version)
My Reaper Tips&Tricks: https://www.youtube.com/user/vanhaze2000/playlists
vanhaze is offline   Reply With Quote
Old 10-30-2020, 10:29 AM   #6
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 2,129
Default

OK cool, thanks for the feedback, maybe I should add it to ReaPack.
Edgemeal is offline   Reply With Quote
Old 10-30-2020, 12:28 PM   #7
vanhaze
Human being with feelings
 
vanhaze's Avatar
 
Join Date: Jul 2012
Location: Netherlands
Posts: 5,094
Default

Yes, that would really nice, such a useful and welcome Script !
__________________
Reaper - OSX (always latest version)
OSX Catalina (always latest version)
My Reaper Tips&Tricks: https://www.youtube.com/user/vanhaze2000/playlists
vanhaze is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:57 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.