pmb6tz/windows-desktop-switcher

Add ability to create a number of empty desktops on launch

Aran-Fey opened this issue ยท 5 comments

I don't like to create desktops on demand, so I would like the script to create 9 empty desktops when it's launched.

I've achieved this with the following code:

createInitialDesktops()
{
    global DesktopCount, CurrentDesktop, NumInitialDesktops

    OutputDebug, Creating %NumInitialDesktops% initial desktops

    Current := CurrentDesktop

    Loop, % NumInitialDesktops - DesktopCount
    {
        createVirtualDesktop()
    }

    OutputDebug, Switching back to desktop %Current%
    _switchDesktopToTarget(Current)
}

The problem with this solution is that NumInitialDesktops must be hard-coded inside the main script, and can't be imported from user_config.ahk. A potential solution could be to introduce a new script user_variables.ahk. (And rename user_config.ahk to user_hotkeys.ahk?)

Hi! Thanks for reaching out.

Add this to user_config.ahk

global NumInitialDesktops = 9
createInitialDesktops()

Add this to desktop_switcher.ahk

createInitialDesktops()
{
    global DesktopCount, CurrentDesktop, NumInitialDesktops

    OutputDebug, Creating %NumInitialDesktops% initial desktops

    Current := CurrentDesktop

    Loop, % NumInitialDesktops - DesktopCount
    {
        createVirtualDesktop()
    }

    OutputDebug, Switching back to desktop %Current%
    _switchDesktopToTarget(Current)
}

It should work, I haven't checked it. Please let us know if it solves it for you.

P.S.
It could be argued that having it like this in the user_config.ahk:

createInitialDesktops(9)

would be a nicer implementation

Oh, I like the createInitialDesktops(9) idea.

Will you include the createInitialDesktops functions in the script, or will users be required to copy/paste it from here if they want this feature?

Thanks for your suggestion!

We try to keep the codebase as minimal as possible to keep the usage and modification of the script usable and accessible. However, I add all these suggestions and solutions as optional modifications in the README.md, I've added your suggestion with the link as well if anyone would like to modify it this way.

Let me know if you'll have any more questions/suggestions and thanks for being part of the community ๐Ÿ‘

Okay, in that case, for the people who can't program, here's a piece of code that can be pasted into user_config.ahk (make sure to put it at the top of the script):

createInitialDesktops(NumInitialDesktops)
{
    global DesktopCount, CurrentDesktop

    OutputDebug, Creating %NumInitialDesktops% initial desktops

    Current := CurrentDesktop

    Loop, % NumInitialDesktops - DesktopCount
    {
        createVirtualDesktop()
    }

    OutputDebug, Switching back to desktop %Current%
    _switchDesktopToTarget(Current)
}

createInitialDesktops(9)

Thanks :) Feel free to close the issue if it has been resolved ๐Ÿ‘