Is there a way to achieve this using autohotkey: I want some windows to be always at the top right of the taskbar no matter how many programs I opened. So, for exmaple, currently it is like this. But, I want notepads always to be on the far right of the taskbar. So, for example like this. So, No matter how many programs I open, I want on the taskbar always notepads to be on the far right.

I'm using windows 8.1 and the latest version of AutoHotkey. Some explanations: I don't want notepads' window itself to be on the far right of the screen. No, but instead I want just icon on the taskbar of notepad to be on the far right. So, if I for example open new programs, I want the icon to be automatically moved to the right, so that no icons be after notepads' icon.

I searched on internet and I didn't find anything useful or similar. So, what I'm trying to do is to make notepads' icons always at the right. I don't care if all notepads I open will be moved to the right or just opened ones to be on the right, it doesn't matter, I just open 4 notepads and keep them until I turn off my computer, so I will never close them.

How to achieve it? I am sure there must be a way because AutoHotkey is very good software and has a lot of enhancements.

Thank you in advance. This is my first question on this site, so please be respectful. Thank.

  • If anything is confusing or unclear due to my bad english, tell me and I'll briefly and clearly explain it. – user782364756 Aug 29 '17 at 6:00
  • @Biswa. I'm not sure what do you are saying. What do you mean by "select the opened taskbar item with Win key". Am I supposed to do it in AutoHotkey script, or manualy? Can you please explain, or even better post a screenshot. – user782364756 Aug 31 '17 at 12:16
  • On your keyboard hit - Windows Key + number key. Number keys correspond to the order that the application shows in your task bar from left to right/ top to bottom. – Biswapriyo Aug 31 '17 at 12:24
  • @Biswa. I'm still not sure what do you mean. When I click WinKey + Number, then it opens the item from taskbar coresponding to that number. However, that is not what I'm asking. I asked how to make Notepad be always last icon on the taskbar no matter how many programs I open (notice that not all programs are pinned to taskbar). Either I don't understand you, or you don't understand the question. – user782364756 Aug 31 '17 at 12:29

AFAIK the only way to move icons on taskbar is to drag them, so this is a AHK script that does the procedure programmatically:

    toggle = true
    Window = 0
    while (toggle) {
        OldWindow = %Window%
        WinGet Window, List

        if (Window > OldWindow) {
            SetTitleMatchMode, RegEx
            IfWinExist, Notepad$
            } Else {
                ; MsgBox Cannot find Notepad window.
            ; absolute coordinate
            CoordMode Pixel, Screen
            CoordMode Mouse, Screen
            Sleep, 100 ; wait for the Notepad icon to be fully highlighted, because Windows have animation of lighting icon
            ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *5 *TransWhite D:\np.bmp
            ; allow some variation because Windows have anti-aliasing etc.

            ; ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *10 *Icon1 %A_WinDir%\system32\notepad.exe
            ; because of some reason the above command does not work
            if ErrorLevel = 2
                MsgBox Could not conduct the search.
            else if ErrorLevel = 1
                MsgBox Icon could not be found on the screen.
            else {
                MouseGetPos OldX, OldY
                SetDefaultMouseSpeed, 0
                MouseMove, %FoundX%, %FoundY%
                Click down left
                MouseMove, A_ScreenWidth, %FoundY% ; move the mouse all the way to the right
                Click up left
                MouseMove, %OldX%, %OldY% ; move mouse to old position

        Sleep, 500 ; can be omitted

    toggle = false


  • Because of some reason, I can't use *Icon1 %A_WinDir%\system32\notepad.exe or similar, you need to provide a file D:\np.bmp consists of Notepad tray icon when Notepad is in focus.
  • Press ^F1 to turn on, ^F2 to turn off.
  • The part used for dragging Notepad task icon executes every time number of windows reported by WinGet increase, i.e., when you open a new window.
  • Notepad window is on focus every time it is dragged to the right.
  • I don't know any way to run command every time except using an infinite loop (while (toogle)). That may consume CPU.
  • Well, I tested it and it works. However, this is far away from good. For example, it deselects the window which was in focus before moving notepad, searching notepad icon on screen is bad practice, it may appear somewhere else (i.e. in folder) which may cause moving files around, also every time an "alt" mesage is raised (place cursor over something) it counts as a new window and notepad is moved. Another problem is because it is very ugly, disturbing and annoying to see notepad icon flying to the right and then comming back. It should be undetectable and unobservable, – user782364756 Sep 4 '17 at 7:22
  • I simply want it to "jump" to the deserved position without influencing anything other. – user782364756 Sep 4 '17 at 7:22
  • I understand it's not good, but - AutoHotkey's main function is to simulate some macro of keyboard/mouse. The only way I know is to drag, and drag cause animation. The other issues (e.g., search only in taskbar, detect correctly when a new taskbar icon appear or refocus the last window) may be solvable. – user202729 Sep 4 '17 at 7:57
  • I will be satisfied if you just improve these three thing: 1) search only in taskbar (not in entire screen), 2) move notepad only when new taskbar icon appears (not when wny new window appear) and 3) Refocus old window. These improvements will definitelly reduce the number of times notepad is moving and will not trigger moving when "alt" message is raised. – user782364756 Sep 4 '17 at 9:45
  • 1
    @user782364756 – maybe you could remap your mind to keep the Notepad leftmost instead of rightmost. This will resolve all the problems in elegant way. – miroxlav Sep 4 '17 at 11:37

I am not aware of any built-in or low-bar solution for this problem. If you really need this functionally I guess you would have to craft your own helper app that allows you to specify a process and rearrange its window button on the task bar. This can be achieved, but requires some knowledge of Win32 and C++/C#.I tried it for 30 minutes (my personal limit).

This is what I did: This thread is the perfect starting point: How to get the processes that have systray icon Point 6. Gives you a working solution for outdated (32bit) versions of Windows: A tool to order the window buttons in your taskbar Unfortunately, it does not work under 64 bit OS and Windows 10.

Nonetheless, some discoveries I made during my exploration with the sample provide in 6: To find the Taskbar on Window 10, use the following code:

//IntPtr hToolbar = User32.FindWindowEx( hTask, IntPtr.Zero, "ToolbarWindow32", null ); xp +
IntPtr taskBarWnd = User32.FindWindowEx(hTask, IntPtr.Zero, "MSTaskListWClass", null);

You will need a 64 bit definition of the TBBUTTON struct:

public struct TBBUTTON
    public int iBitmap;
    public int idCommand;
    private struct TBBUTTON_U
        public byte fsState;
        public byte fsStyle;
        private IntPtr bReserved;
    private TBBUTTON_U union;
    public byte fsState { get { return union.fsState; } set { union.fsState = value; } }
    public byte fsStyle { get { return union.fsStyle; } set { union.fsStyle = value; } }
    public UIntPtr dwData;
    public IntPtr iString;

This should give you a good starting point for a roll-your-own solution.

Another helpful starting point could be the 7+ Taskbar Tweaker, which has some very handy taskbar tweaks (as the name suggests). 7+TT also offers a library that does most of the (black) magic for you and could also server as a starting point for a DIY solution (plus it works even on Windows 1607. Take a look at the print taskbar contents sample; AppId is here a good hook to find the right Taskbar Button Window/Button Group).

Good luck.

With the help of the 7+TT Lib your goal is pretty easy to achieve.
Here is a working sample I have made (the archive contains the source of my sample as well as a binary in the x64/Release folder, called taskbar_pusher, that should work with Windows 7 - 10 up to the latest release v1709).

You have to specify the AppId of the button group you would like to push to the rear end of your taskbar like this as command line parameter:

./taskbar_pusher {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\notepad.exe

You get the AppId from the CLI output of my tool.
You should be able to call it parameterize like this with AHK (though I am not very familiar with AHK).

PS: I had some problems with my secondary taskbar and therefore disabled the code to detect it.

  • Interesting. I like your answer because you've decided to focus on the goal and completelly omitted the AutoHotkey tool (because as it seems AutoHotkey cannot help in this case). I've already made some Win32 aplications in C++, so I'll give it a try. Thanks for useful links. – user782364756 Sep 5 '17 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.