Forced switching between Spaces when opening Microsoft Office files

mission-controlms officespaces

Since time immemorial, opening a Microsoft Office file has had the side effect of restoring an already-open window in the same application before displaying the newly opened file's window. This was mildly annoying for multitaskers who minimized windows associated with tasks other than their current one, forcing them to re-minimize a window not relevant to the task at hand.

I suspect that this same behavior is now to blame for a truly maddening side effect when using Spaces with a different space for each task: Opening, say, a Word document still causes the most recently active Word document window to be brought to the front, so if that window is in a different space, Spaces switches to that space– a context-blowing action.

For what it's worth, I'm using Office 2011 on Mountain Lion, though the behavior seems to be the same on Mavericks and previous versions. I've already unchecked the Mission Control options, "Automatically rearrange spaces based on most recent use" and "When switching to an application, switch to a space with open windows for that application." This seems to work for most apps– e.g., opening a PDF file in Adobe Reader when another PDF file is already open in a different space doesn't trigger a switch to that space– just not MS Office.

Does anyone know of an Office setting or hack that would prevent this?

This question is probably related to Microsoft Word Forcing “Spaces” Switching.

Best Answer

I've long experienced this problem, too. Haven't found any 'good' solutions, so put together some Applescripts that partially address the problem. It's very much a kludge and not a perfect solution, and deploying the scripts in a given user's workflow is a matter of individual taste.

Here's code to open an MS Word document in a space that doesn't have any Word windows without first triggering a shift to a space with a Word window open:

tell application "System Events" to tell process "Microsoft Word" to tell menu bar 1 to tell menu bar item 3 to tell menu 1 to click menu item 1 --open
tell application "Microsoft Word" to activate

And this script will close an MS Word document without triggering a switch to another space (if it was the last Word window open in the current space):

--Is there another window of the app in this space? If so, don't need to shift to another app before closing
tell application "System Events" to tell application process "Microsoft Word" to set _theWindows to name of every window as list
set WinNum to number of strings of _theWindows --(Office puts weird other things in the list)
if WinNum = 1 then --i.e., it is the only window in the space
    tell application "System Events" to keystroke tab using command down --switch to another app
    delay 0.1
    tell application "System Events" to set visible of application process "Microsoft Word" to true --in case there is a close dialog I still need to see
    delay 0.1
end if
tell application "System Events" to tell process "Microsoft Word" to tell menu bar 1 to tell menu bar item 3 to tell menu 1 to click menu item "Close" --close