Skip to content

Instantly share code, notes, and snippets.

@sng2c
Last active December 19, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sng2c/5866288 to your computer and use it in GitHub Desktop.
Save sng2c/5866288 to your computer and use it in GitHub Desktop.
AutoHotKey와 Perl을 이용하여, VM에 띄워진 Window가 깜빡일 때 반응하여, Host Linux의 Notify로 띄워주는 스크립트들. Notify on a host os with blinking taskbar's title from a guest os on VM by AHK and Perl scripts.
#SingleInstance force
#WinActivateForce ; this may prevent task bar buttons from flashing when different windows are activated quickly one after the other
DetectHiddenWindows, On
Script_Hwnd := WinExist("ahk_class AutoHotkey ahk_pid " DllCall("GetCurrentProcessId"))
DetectHiddenWindows, Off
; Register shell hook to detect flashing windows.
DllCall("RegisterShellHookWindow", "uint", Script_Hwnd)
OnMessage(DllCall("RegisterWindowMessage", "str", "SHELLHOOK"), "ShellEvent")
ShellEvent(wParam, lParam) {
if (wParam = 0x8006) ; HSHELL_FLASH
{ ; lParam contains the ID of the window which flashed
FlashWindowEx(lParam, FLASHW_STOP:=0, 0, 65535)
WinGetTitle title, ahk_id %lParam%
Run c:\strawberry\perl\bin\wperl.exe send2linux.pl "'%title%'창이 깜빡입니다."
WinGet, hwndWasFocused, ID, A ; remember which window originally had the focus
BlockInput, On ; we can't stop keystrokes from being lost, but we can stop them from going to the wrong application
WinActivate, ahk_id %lParam%
WinActivate, ahk_id %hwndWasFocused%
BlockInput, Off
}
}
; thanks to SKAN http://www.autohotkey.com/forum/post-280244.html#280244
;
; dwFlags can be a bitwise combination of:
; FLASHW_ALL := 3 ; Flash both the window caption and taskbar button. This is equivalent to setting FLASHW_CAPTION|FLASHW_TRAY flags.
; FLASHW_CAPTION := 1 ; Flash the window caption.
; FLASHW_STOP := 0 ; Stop flashing. The system restores the window to its orig. state.
; FLASHW_TIMER := 4 ; Flash continuously, until the FLASHW_STOP flag is set.
; FLASHW_TIMERNOFG := 12 ; Flash continuously until the window comes to foreground.
; FLASHW_TRAY := 2 ; Flash the taskbar button.
FlashWindowEx( hWnd=0, dwFlags=0, uCount=0, dwTimeout=0 ) {
Static FW="0123456789ABCDEF01234" ; FLASHWINFO Structure
NumPut(20,FW), NumPut(hWnd,FW,4), NumPut(dwFlags,FW,8), NumPut(uCount,FW,12), NumPut(dwTimeout,FW,16)
Return DllCall( "FlashWindowEx", UInt,&FW )
}

Host 리눅스 쪽

  1. host인 리눅스 쪽에서는 perl모듈인 Mojolicious가 필요하고, notify-send 명령이 사용가능해야 한다.
  2. perl notify_recv.pl daemon 으로 웹서버를 띄운다. 포트값은 기본으로 3000번

VM내 윈도우 쪽

  1. VM안의 Windows는 Strawberry perl과 AutoHotKey를 설치한다.
  2. AlertFlash.ahk 와 send2linux.pl 을 함께 둔다.
  3. send2linux.pl 내의 IP값을 ipconfig명령의 결과에 보이는 Gateway 로 잡고 포트도 맞춰준다.
  4. AlertFlash.ahk를 실행한다.

Please translate this file to your language

#!/usr/bin/env perl
use 5.018;
use Mojolicious::Lite;
get '/' => sub {
my $self = shift;
my $title = $self->param('title');
my $desc = $self->param('desc');
`notify-send "$title" "$desc"`;
say $title;
$self->render('index');
};
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
% title 'Welcome';
OK
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>
use 5.016;
use LWP::Simple;
use Encode;
my $title = $ARGV[0];
$title = Encode::decode('cp949',$title);
get 'http://10.0.2.2:3000?title='.$title; #여기 IP를 ipconfig 의 결과에 나온 게이트웨이로 맞춘다.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment