microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
111.42k stars 6.56k forks source link

[Workspaces] Saving and loading File Explorer with tabs #34664

Open teijiIshida opened 2 months ago

teijiIshida commented 2 months ago

Description of the new feature / enhancement

All tabs in the File Explorer should be saved and opened when launching the workspace.

Scenario when this would be used?

Currently, Workspace is able to open multiple File Explorer instances. However, adding a feature to allow saving/loading File Explorer with (the user saved) tabs would be nice for organization or small screen setups.

Supporting information

No response

plante-msft commented 2 months ago

Using this issue to track related File Explorer multiple tabs requests.

Right now, this is a limitation of the File Explorer app's allowed CLI arguments - only the first path passed is respected.

There are solutions that involve using scripting / batch files for opening multiple FE tabs in one instance, and that is potentially a workaround we could look into.

NnWinter commented 3 weeks ago

So this means that, for now, we can only rely on these inconvenient and somewhat unreliable scripts circulating online (vbs in this case) to achieve this functionality...

Hopefully, Windows will implement this feature soon.

VBS Script

Set oShell = CreateObject("WScript.Shell")
oShell.Run("""C:\windows\explorer.exe""")
WScript.Sleep 1000
oShell.AppActivate "Explorer"
WScript.Sleep 500
oShell.SendKeys "%d"
WScript.Sleep 300
oShell.SendKeys "<<Path of folder 1>>" ' folder 1
WScript.Sleep 300
oShell.SendKeys "{ENTER}"
WScript.Sleep 500
oShell.SendKeys "^t"
WScript.Sleep 300
oShell.SendKeys "%d"
WScript.Sleep 300
oShell.SendKeys "<<Path of folder 2>>" ' folder 2
WScript.Sleep 300
oShell.SendKeys "{ENTER}"
WScript.Sleep 1000
oShell.SendKeys "^t"
WScript.Sleep 300
oShell.SendKeys "%d"
WScript.Sleep 300
oShell.SendKeys "<<Path of folder 3>>" ' folder 3
WScript.Sleep 300
oShell.SendKeys "{ENTER}"

%d = Alt + D = Set focus to the address bar of the current window
^t = Ctrl + T = Open new tab
Path doesn't need to be escaped and is the same as typing in the address bar.

Crate workspace

You can first capture an explorer instance and save the workspace, then modify it based on this.

Edit workspace json file

And need to edit the workspace.json file in the %AppData%\Local\Microsoft\PowerToys\Workspaces directory
(Note: this is a risky operation. Ensure you know what you're doing. It's recommended to ⚠backup the file before editing to avoid damaging other saved Workspaces).

Sometimes, the document isn't properly formatted, so you can use tools like JSON formatting in VSCode to make editing easier.

Then, make the following changes in the new workspace:

{
    "id": "......",
    "name": "The name of your workspace",
    "creation-time": ......,
    "last-launched-time": ......,
    "is-shortcut-needed": ......,
    "move-existing-windows": ......,
    "monitor-configuration": [
        ......
        ],
    "applications": [
        {
            "application": "Vbs",
            "application-path": "D:\\Example\\Example.vbs",
            "title": "Vbs",
            "package-full-name": "",
            "app-user-model-id": "",
            "command-line-arguments": "",
            "is-elevated": ......,
            "can-launch-elevated": ......,
            "minimized": ......,
            "maximized": ......,
            "position": { "X": 0, "Y": 0, "width": 800, "height": 600},
            "monitor": 1
        }
    ]
}

Run

After saving the JSON file, ensure that the Workspace Editor is closed (since saving the workspace will overwrite the file). Reopen the Workspace Editor, and you should now see a VBS script icon. If the paths are configured correctly, it should run directly. If the path is incorrect, a warning symbol, like ⚠, will appear at the beginning to notify you of the issue.

After running the script, wait for the automation to complete and open the tabs before proceeding. If the automation script fails due to system lag, you might want to experiment with increasing the WScript.Sleep times to ensure all actions are properly registered. Therefore, I believe the reliability of this method is not very high, and it should be used cautiously.