将应用程序窗口还原到其原始空间


25

重新打开应用程序时,无论其原始位置如何,其所有窗口最终都位于第一个Space上:

原始布局:一个应用程序有两个打开的窗口,每个窗口位于一个单独的空间中

+-----[ Space 1 ]-----+  +-----[ Space 2 ]-----+
|                     |  |                     |
|  [Chrome window 1]  |  |  [Chrome window 2]  |
|                     |  |                     |
|                     |  |                     |
+---------------------+  +---------------------+

应用程序重启后布局不正确:两个窗口都在第一个空格中

+-----[ Space 1 ]-----+  +-----[ Space 2 ]-----+
|                     |  |                     |
|  [Chrome window 1]  |  |                     |
|  [Chrome window 2]  |  |                     |
|                     |  |                     |
+---------------------+  +---------------------+

是否有设置或应用程序可以使应用程序在退出应用程序之前在其原来位于的空间中还原其窗口?


如果您要为各个窗口提供单独的空间,您难道不能只使用全屏模式,它实际上是在做同样的事情吗?
William T Froggard

4
全屏不是我想要的。我典型的工作流程是为我正在从事的每个项目分配专用的空间。因此,我有许多活动的Space,每个空间通常都有一个Chrome窗口,一个编辑器窗口,一个终端窗口等。而且,我不想每次重新启动,重新启动应用或应用程序崩溃。因此,我对您在上图中看到的内容真的很感兴趣:让应用程序或操作系统记住退出应用程序之前每个单独窗口的空间。
2015年

11
不知道为什么人们对OP的问题有疑问。我的印象是人们不了解太空和任务控制的工作原理。从我的角度来看,我经常看到OP的问题,并且行为在各种应用程序(例如Safari和Finder窗口)中不一致。有时窗户会进入其各个空间,有时则不会。
Vzzdak

@Vzzdak关于行为不一致的要点。忘了说。
Jakub Roztocil,2015年

1
尽管这个问题来自2015年,但在2019年仍然是完全相关的。不仅仅是Chrome。例如,我在Finder窗口中看到了相同的问题。
Jamie Cox

Answers:


8

Chromium中存在一个错误#74812。投票吧!

关于超级用户的相同问题

编辑:它是在最新的开发版本(Chrome 79)中实现的!

尽管默认情况下,符合Apple的UI要求,但是如果您退出带有Cmd-Q的Chrome,此功能仍将无法还原工作区。引用sfy,功能作者:

对于希望Chrome始终将窗口还原到其原始空间的人,您可以通过在终端窗口中运行以下命令来设置该窗口(对于Canary,请使用com.google.Chrome.canary):

defaults write com.google.Chrome NSWindowRestoresWorkspaceAtLaunch -bool YES

要恢复默认行为,请运行:

defaults delete com.google.Chrome NSWindowRestoresWorkspaceAtLaunch


0

我没有完整的答案,但是今天,我使用applescript在这个问题上开始了不错的尝试。以下Applescript大约完成了一半的工作。它报告在每个桌面上打开的每个应用程序的所有窗口。下一步是将所有这些记录在文件中,然后在重新启动后实施脚本以重新分发Windows:

--This applescript reports a list of application windows present on each desktop
--This is only a sample script intended to eventually be used to restore all application windows to their pre-reboot desktops

tell application "System Events"

    set windows_string to ""
    set numDesktops to (first paragraph of (do shell script "strings ~/Library/Preferences/com.apple.spaces.plist | grep -c ^\\\\$")) + 1
    --the following tcsh command can determine the number of desktops:
    -- @ x = ( `strings ~/Library/Preferences/com.apple.spaces.plist | grep -c '^\$'` + 1 ); echo $x

    -- switch to the first desktop:
    repeat with aDesktop from 1 to numDesktops
        key code 123 using {control down}
    end repeat

    repeat with aDesktop from 1 to numDesktops

        set windows_string to windows_string & return & return & "Desktop " & (aDesktop as string) & return
        delay 1
        get (the name of every application process whose class of windows contains window)

        repeat with P in the result

            set windows_string to windows_string & return & return & P & return

            get (every window of process (contents of P) whose value of attribute "AXMinimized" is false)

            repeat with W in the result

                set window_name to ((name of W) as string)

                --Stickies window names can be multi-line, so this trims from the first hard return onward
                set better_window_name to (my replacePattern:"[\\n].*" inString:window_name usingThis:"")
                if window_name is not equal to "" then
                    try
                        set windows_string to windows_string & better_window_name & return
                    on error
                        set windows_string to windows_string & "couldn't get window name" & return
                    end try
                end if

            end repeat

        end repeat

        --switch to the next desktop
        key code 124 using {control down}

    end repeat

    display dialog "List of windows on this desktop: " & return & return & windows_string

end tell

--Call like this: set res to my replacePattern:"\\s+" inString:"1 subtratcing-these: -2 3 4" usingThis:"-"
use framework "Foundation"
use scripting additions

on replacePattern:thePattern inString:theString usingThis:theTemplate
    set theRegEx to current application's NSRegularExpression's regularExpressionWithPattern:thePattern options:0 |error|:(missing value)
    set theResult to theRegEx's stringByReplacingMatchesInString:theString options:0 range:{location:0, |length|:length of theString} withTemplate:theTemplate
    return theResult as text
end replacePattern:inString:usingThis:

这是我得到的结果对话框的示例:

List of windows on this desktop: 



Desktop 1


iTunes
MiniPlayer


FluidApp
Found 626 tickets


Stickies
useful commands
System Config Notes
Special characters
Profile where a python scri…
XEMacs Tricks
Terminal Tips


Messages
Messages (3 unread)


FluidApp
Found 626 tickets


Slack
Slack - Princeton NPLC


FluidApp
Found 626 tickets


Desktop 2


iTunes
MiniPlayer


FluidApp
Found 626 tickets


Stickies
DAI


Messages
Messages (3 unread)


FluidApp
Found 626 tickets


Slack
Slack - Princeton NPLC


FluidApp
Found 626 tickets


Desktop 3


iTunes
MiniPlayer


Finder
Searching “Scripts”
Searching “Scripts”
Searching “Scripts”


FluidApp
Found 626 tickets


Stickies
RPST
Issues to resolve with RPST…


Messages
Messages (3 unread)


FluidApp
Found 626 tickets


Terminal
Terminal — -csh


TextEdit
Untitled 35.txt
Untitled 34.txt
Untitled 27.txt
Untitled 15.txt


Slack
Slack - Princeton NPLC


Safari
AppleScript: Essential Sub-Routines
Using Applescript to Execute a Complicated Keystroke - Stack Overflow
How to restore windows to their original desktops after reboot? - Ask Different


Script Editor
Untitled.scpt
Untitled 4.scpt
Untitled 3.scpt
paste_file_contents.scpt
Untitled 2.scpt


FluidApp
Found 626 tickets


Automator
Subtract.workflow (Quick Action)


Desktop 4


iTunes
MiniPlayer


FluidApp
Found 626 tickets


Stickies
GALAXY


Messages
Messages (3 unread)


FluidApp
Found 626 tickets


Terminal
Terminal — -bash
???c7??? 8yc`?h=??'?]b?c??k?k????Ԫ??m??d+ — -bash


Slack
Slack - Princeton NPLC


FluidApp
Found 626 tickets


Desktop 5


iTunes
MiniPlayer


FluidApp
Found 626 tickets


Stickies
TREEVIEW
When you start to work on a…
TreeView stats, legend, & d…
DATE OF SUBMISSION: 


Messages
Messages (3 unread)


FluidApp
Found 626 tickets


Slack
Slack - Princeton NPLC


FluidApp
Found 626 tickets


Desktop 6


iTunes
MiniPlayer


FluidApp
Found 626 tickets


Stickies
ALIZZI


Messages
Messages (3 unread)


FluidApp
Found 626 tickets


Slack
Slack - Princeton NPLC


FluidApp
Found 626 tickets


Desktop 7


iTunes
MiniPlayer


FluidApp
Found 626 tickets


Stickies
GARCIA


Messages
Messages (3 unread)


FluidApp
Found 626 tickets


Slack
Slack - Princeton NPLC


FluidApp
Found 626 tickets


Desktop 8


iTunes
MiniPlayer


FluidApp
Found 626 tickets


Stickies
EMILIA


Messages
Messages (3 unread)


FluidApp
Found 626 tickets


Slack
Slack - Princeton NPLC


FluidApp
Found 626 tickets
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.