gpt4 book ai didi

windows - Cygwin:创建 Windows 通知并在单击通知时聚焦程序

转载 作者:行者123 更新时间:2023-12-04 07:20:40 26 4
gpt4 key购买 nike

我想要一个 cygwin shell 脚本来创建一个 Windows 通知(您在右下角看到的那些事件之一)。当您单击通知时,我希望它能够将另一个应用程序带入焦点。
下面是我将如何使用它:从命令行,我运行测试。当他们完成时,我希望收到通知。如果我单击该通知,我希望 cygwin 重新聚焦,以便我可以决定下一步要做什么。

最佳答案

好吧,弄清楚这是一个巨大的痛苦,即使如此,这个解决方案也远非理想 - 但它确实有效,所以值得写下来。
创建通知并不难。聚焦应用程序并不难。但是很难创建一个在单击时聚焦窗口的通知。
这是一个脚本:

set -ex

notification_exit_code=0 # default value, exited successfully
# create a notification that says "Build Done". When notifu64 exits, it's exit code tells why it exited (see below)
notifu64.exe /i 'C:\\cygwin64\\Cygwin-Terminal.ico' /t info /p "Build Done" /m "Build Done" || notification_exit_code=$?

# these are some of the ways the notification could have exited
user_clicked_on_notification=3
notification_timeout=4
user_clicked_on_notification_icon=7
if [[ "$notification_exit_code" -eq "$user_clicked_on_notification" ]] || [[ "$notification_exit_code" -eq "$user_clicked_on_notification_icon" ]]
then
# The order of the steps is very important or else the window will remain in the background. I figured out these steps from here: https://stackoverflow.com/a/59819671/61624
nircmd win activate process mintty.exe
# I'm not sure why, but "activate" resizes the window. This puts it back the way it always is on my computer: maximized
nircmd win max process mintty.exe
nircmd win settopmost process mintty.exe 1
nircmd win settopmost process mintty.exe 0
nircmd win focus process mintty.exe
# This is 99% of the way there. The problem is the window still doesn't have focus, even though it brings it to the front. It's the ShellExperienceHost.exe that maintains it, and I can't figure out how to stop that from happening. I have to manually click on the window to give it focus
# And here's the workaround I wish I didn't have to do: Because the window is going to be full-sized, by moving the mouse up, I know with certainty that I won't be clicking on the taskbar (because it's docked on the bottom of my screen).
nircmd sendmouse move 0 -1000
# Now I click, to bring the window I've switched to into focus.
nircmd sendmouse left click
fi
if [[ "$notification_exit_code" -eq "$notification_timeout" ]]
then
# this makes the taskbar icon highlighted to remind me that the build is done even if I don't want to look at it immediately
nircmd win flash process mintty.exe
fi
notifu64.exe是一个可以创建 Windows 通知的命令行工具。
nircmd是一个命令行工具,可以控制 Windows 操作系统的各个方面。在这个脚本中,我用它来 control application windows .

关于windows - Cygwin:创建 Windows 通知并在单击通知时聚焦程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68522402/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com