3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

2つのウインドウを一発で最前面にする

Last updated at Posted at 2016-02-01

素人の備忘録。
適当にやったら動いただけなのできっとどこか間違いがある。
というか車輪の再発明感半端ない。

(2016/9/6追記)
Windows10やMacなら素直に仮想デスクトップを使おう。

動機

画面左のエディタでLaTeXを書いて、右のpdfビューアで見るといった具合に、左右にウインドウ2つ並べて作業することが多い。
そのままブラウザで調べたりもする。
ところがエディタを最前面に戻してもビューアはブラウザの向こう側。
ビューア空気読め。

解決策

要はエディタとビューアが一発で最前面にくるボタンがほしい。

Windowsの場合

AutoHotKeyを使う。
Alt+vでエディタとビューアが最前面になって、エディタがアクティブになる。
エディタとビューアが両方起動していないとなにもおこらないはず。
ついでにエディタが終了したらビューアとAutoHotKeyが終了するようにした。
(2016/4/20追記)
WinActivateを連続で使うとビューアにフォーカスがまた移ってしまったり弊害があったのでビューアはTopにするだけにした。
またAlt+vでエディタ+ビューアと直前の最前面ウインドウを交互に最前面にできるようにした。
winset, topが効かなかったのでAlwaysOnTopを2回使用。
参考

Activate_Vim_and_pdf.ahk
;; vimとSumatraPDFを同時に最前面にする
# IfWinExist ahk_exe SumatraPDF.exe
IfWinExist, ahk_exe gvim.exe
{
    Process, WaitClose, gvim.exe
    {
        Process, Close, SumatraPDF.exe
        ExitApp
    }
    !v::
        IfWinActive, ahk_exe gvim.exe
        {
            WinSet, Bottom, , ahk_exe gvim.exe
            WinSet, Bottom, , ahk_exe sumatraPDF.exe
            WinActivate, %lastATitle%
            Return
        }
        Else
        {
            WinGetActiveTitle, lastATitle
            WinSet, AlwaysOnTop, On, ahk_exe sumatraPDF.exe
            WinSet, AlwaysOnTop, Off, ahk_exe sumatraPDF.exe
            WinActivate, ahk_exe gvim.exe
            Return
        }
}
# IfWinExist

Macの場合

AppleScriptを使う。
スクリプトエディタで以下のように。

Activate_Vim_and_pdf.app
-- VimとSkimを最前面にする
if application "MacVim" is running then
	if application "Skim" is running then
		tell application "Skim"
			activate
		end tell
		tell application "MacVim"
			activate
		end tell
	end if
end if

これをファイルフォーマット:アプリケーションとして保存。
実行するとエディタとビューアが最前面になり、エディタがアクティブになる。
エディタとビューアが両方起動していないとなにもおこらないはず。
後は適当な手段でホットキーで起動できるようにする。
自分の場合Snapを使用。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?