6

I have an application/window on Desktop 1 (OS X Lion) and I'd like to move it to Desktop 3. Any insights on how to do this? Not as big a deal, but if possible I'd like to ensure there are 3 and only 3 Desktops available.

ryonlife
  • 6,563
  • 14
  • 51
  • 64
  • By "desktop", are you referring to Lion's version of Spaces? – tkbx May 12 '12 at 13:42
  • I too would like to learn how to do this. Specifically, after a reboot, I want to redistribute a single app's windows back to their original (virtual) desktops. I was thinking I could do this by calling `open -a app -F` and then switch desktops and open specific files, which could partially work for saved docs BUT -F doesn't work on Untitled documents. Those always open on whichever desktop you're on when you start the app. – hepcat72 Jul 10 '19 at 15:34

3 Answers3

3

This answer should offer clues on how to do place applications, specifically...

tell application "System Events"
    set x to application bindings of spaces preferences of expose preferences
    set x to {|com.apple.textedit|:4} & x  -- Have TextEdit appear in space 4
    set application bindings of spaces preferences of expose preferences to x
end tell

I would imagine moving a window is not too different.

Community
  • 1
  • 1
Philip Regan
  • 5,005
  • 2
  • 25
  • 39
2

I realize this question is old, but in case anyone still needs this functionality, I thought I'd share my solution.

Because there aren't any real scripting exposures in Mission Control, you'll need to manipulate the cursor and thus will need access to the Objective-C bridge. This requires using the JXA variant of AppleScript, but still allows things to run natively without any plugins.

If you're still interested I've shared the solution on my GitHub repository, stephan-hates-osascript.

stephancasas
  • 615
  • 3
  • 12
  • Upvoted! This looks like the answer to our prayers! Thanks for doing it! I noticed your script only works for the frontmost window. Would you kindly be able to share examples how to make it work for several apps? My goal is to run a script on startup and place "My App A" on Space 1, "My App B" on Space 3, etc etc. Do you think your script would support that? – Luiz Nov 22 '22 at 13:43
  • 1
    @Luiz, instead of using the included function `FrontmostWindow()`, which relies on `FrontmostApp()`, you can write logic to interface with `System Events` and get the windows you want. For example, if I wanted the first window of *Brave Browser* `Application('System Events').applicationProcesses.byName('Brave Browser').windows.at(0);` – stephancasas Nov 22 '22 at 16:01
-3

Moving a window works while switching to different desktops with a keyboard shortcut.

With the mouse, click and hold the title bar as if you are moving the window around your desktop, then press ctrl+3. Ctrl+3 has to be mapped to move to desktop 3 in the keyboard shortcuts interface. Ctrl+Right twice also works. Then release the mouse button.

NerdMachine
  • 155
  • 1
  • 3