Hi Kenny,
I don’t think it is possible to move a window while staying on the current Space. However, in theory you could make the macro take you back to the original Space, after the window has been moved.
For this to work the macro has to know the current Space at macro launch. I think this is not really trivial.
The most convenient thing would be to get the current Space via AppleScript. But I don’t know if this is possible; I doubt it. (@ccstone ?)
You can get the current Space from UserDefaults:
defaults read com.apple.spaces
Click here to see a (shortened) sample output of that command
alice:~ tom$ defaults read com.apple.spaces
{
SpacesDisplayConfiguration = {
"Management Data" = {
Age = "29576.78084978485";
Double = {
[…]
] };
"Management Mode" = 1;
Manager = {
[…]
};
Monitors = (
{
"Current Space" = {
ManagedSpaceID = 1;
id64 = 1;
type = 0;
uuid = "";
wsid = 1;
};
"Display Identifier" = Main;
Spaces = (
{
ManagedSpaceID = 1;
id64 = 1;
type = 0;
uuid = "";
wsid = 1;
},
{
ManagedSpaceID = 6;
id64 = 6;
type = 0;
uuid = "AB4ACAF6-1F1B-4400-8A8D-64DBC1238047";
},
{
ManagedSpaceID = 7;
id64 = 7;
type = 0;
uuid = "CF6BCFEF-B85B-43F2-916D-2332A76E1F37";
}
);
},
{
"Current Space" = {
ManagedSpaceID = 2289;
id64 = 2289;
type = 0;
uuid = "C041359B-E97C-44F9-B8BF-051FD70004ED";
};
"Display Identifier" = "F03B120E-3C33-328F-0325-8C9341661C14";
Spaces = (
{
ManagedSpaceID = 2289;
id64 = 2289;
type = 0;
uuid = "C041359B-E97C-44F9-B8BF-051FD70004ED";
}
);
}
);
Primary = {
[…]
};
Secondary = {
[…]
};
Single = {
[…]
};
Tile = {
[…]
};
};
"Space Properties" = (
{
name = "";
windows = (
168556,
163025,
162520,
168396,
126475,
168366,
168378,
168373,
419,
28326,
34250,
25645,
128,
134246,
84643,
99954,
84670,
78221,
42480,
177,
134,
92861,
37035,
29365,
41199,
124262,
102,
98325,
30851
);
},
{
name = "AB4ACAF6-1F1B-4400-8A8D-64DBC1238047";
windows = (
168556,
126475,
28326,
34250,
25645,
128,
134246,
134,
102,
98325,
30853
);
},
{
name = "CF6BCFEF-B85B-43F2-916D-2332A76E1F37";
windows = (
168556,
126475,
28326,
34250,
25645,
128,
134246,
134,
102,
98325,
159342,
139565,
126115,
146589,
116441,
149,
180,
148736,
117691,
30855
);
},
{
name = "C041359B-E97C-44F9-B8BF-051FD70004ED";
windows = (
29364,
168343,
168266
);
}
);
};
"app-bindings" = {
[…]
};
"spans-displays" = 0;
}
- The “Current Space” is listed for each display (monitor) and can have one or more of several type of IDs:
id64
, ManagedSpaceID
, uuid
and wsid
.
- Furthermore “Space Properties” contains a list of all windows (by window id) that are part of that Space.
So, what you’d have to do in the macro is basically this:
- Extract the appropriate identifier for the current Space of your current display (or of the frontmost window) from the output of the command line, and save it to a variable.
- Move the window to a different Space.
- Go back to the original (saved) Space, either by…
- scripting MissionControl (if possible)
- simulating the keyboard shortcut for the original Space
If you move the window with the arrow keys (⌃⌥⇢ or ⌃⌥⇠), then it should be somewhat simpler:
- In the macro, count how many times you hit the arrow-key shortcut.
- At the end make the macro execute ⌃⇠ (or ⌃⇢) the appropriate number of times.
This should bring you back to the original Space. But this won’t work if you move the window with a number key (for example ⌃⌥3).
Maybe somebody has some better ideas…