If I have several OS-X Terminal.app windows open, how can I move one Terminal window to another space?
I'm happy to use any scripting or programming language to achieve this, but would prefer AppleScript or calls to standard frameworks.
(Note this is to move only one window of an application not all windows.)
Using private calls in Objective-C/C, unofficially listed here
#import <Foundation/Foundation.h>
typedef int CGSConnection;
typedef int CGSWindow;
extern OSStatus CGSMoveWorkspaceWindowList(const CGSConnection connection,
CGSWindow *wids,
int count,
int toWorkspace);
extern CGSConnection _CGSDefaultConnection(void);
int main(int argc, char **argv) {
CGSConnection con = _CGSDefaultConnection();
// replace 2004 with window number
// see link for details on obtaining this number
// 2004 just happened to be a window I had open to test with
CGSWindow wids[] = {2004};
// replace 4 with number of destination space
CGSMoveWorkspaceWindowList(con, wids, 1, 4);
return 0;
}
Standard warnings apply about undocumented APIs: they are subject to breaking.
Based on cobbal's answer, code ported to ruby:
require 'dl';
wid = 2004
dl = DL::dlopen('/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices')
_CGSDefaultConnection = dl.sym("_CGSDefaultConnection", 'I');
CGSMoveWorkspaceWindowList = dl.sym("CGSMoveWorkspaceWindowList", 'IIiII');
con = _CGSDefaultConnection.call();
CGSMoveWorkspaceWindowList.call(con[0], wid, 1, 4);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With