AHK メモ

特定のアプリ専用のスクリプトはそのカテゴリに。気が向き次第拾い集めてくる。


自作/改造スクリプト

ファイルから項目を読み込んでチェックリストを作成する (2005/12/25)

以下のような書式(行頭に・)のテキストを読み込んでリスト化。

・あああああああああああああああああああああああああああああああああああああああ
・いい
・うううううううううううううううううう
  • "Reload"ボタン ⇒ チェックをつけていた項目だけ消える。
  • "New"ボタン ⇒ InputBox?起ち上がって「新規登録」。一番下に付加。
;===============================================================================
; CheckList.ahk - ファイルから項目を読み込んでチェックリストを作成。(2005/12/25)
;===============================================================================

list = %1%	; 第1引数を対象ファイルとする。

gosub Main
return

; チェックリストの作成
Main:
	i := 0
	Loop, Read, %list%
	{
		i += 1
		StringGetPos, dot_pos, A_LoopReadLine, ・
		If dot_pos=0	; ・が一文字目にある行を抽出。
		{
			StringTrimLeft, item, A_LoopReadLine, 2
			listup(item)
		}
	}
	Gui, Add, Button, X55 Default, Reload	; "Reload"ボタンの作成
	Gui, Add, Button, x+25 yp+0 Default, New	; "New"ボタンの作成
	Gui, Show
	
	WinSet, Transparent, 180, CheckList.ahk	; チェックリストウィンドウの透過度
	WinSet, AlwaysOnTop, On, CheckList.ahk	; チェックリストウィンドウを最前面
	
	return

listup(item)
{
	Gui, Add, Checkbox, W200, %item%	; 幅200px
	GUI, Submit
}

; "Reload"ボタンを押した時の挙動
ButtonReload:
	FileMove, %list%, %list%.bak, 1	; 対象ファイルのバックアップ
	Loop, %i%
	{
		GuiControlGet, x%a_index%, , Button%a_index%
		GuiControlGet, s%a_index%, , Button%a_index%, Text
		buf := s%a_index%
		If x%a_index%<>0	; チェックの付いてる項目だけ対象ファイルに書き出す。
			Continue
		else
			FileAppend, ・%buf%`n, %list%
	}
	GUI, Destroy	; 現在のチェックリストウィンドウを破棄
	gosub Main	; 対象ファイルの再読み込み。
	
	return

; "New"ボタンを押したときの挙動
ButtonNew:
	WinSet, AlwaysOnTop, Off, CheckList.ahk
	InputBox, UserInput, 新規登録, , , 200, 90
	If ErrorLevel <> 0
		return
	else
	{
		FileAppend, `n・%UserInput%, %list%
		GUI, Destroy
		gosub Main
		WinSet, AlwaysOnTop, On, CheckList.ahk
	}
	return

; ウィンドウを閉じた時の挙動
GuiClose:
	ExitApp

アクティブなウィンドウの半透明化と最前面化をToggleする (2005/12/14)

ブラウザでとあるサイトを参照しながら、エディタで作業したい時とか。

;===============================================================================
; TransTopmostToggle.ahk - アクティブなウィンドウの半透明化と最前面化をToggleする。(2005/12/14)
;===============================================================================

#Persistent

class =
flag = 0

SetTimer, Reflesh, 1000	;1秒ごとに対象ウィンドウの有無を確認し、無くなっていればこのスクリプトを初期状態に戻す。
return

OnExit, ExitSub
return

;"Win+Alt+T"で本体実行
#!t::
	If class =
	{
		WinGetClass, class, A
		WinGetTitle, title, A
		MsgBox, 4, TransTopmostToggle, "%title%" をTransTopmostToggleの対象にしますか?
		IfMsgBox, No
		{
			class =
			flag = 0
			return
		}
	}
	If flag<>0
	{
		WinSet, Transparent, Off, ahk_class %class%
		WinSet, Topmost, Off, ahk_class %class%
		flag = 0
		return
	}
	else
	{
		WinSet, Transparent, 200, ahk_class %class%	;ウィンドウの不透明度(200/255)
		WinSet, Topmost, On, ahk_class %class%
		flag = 1
		return
	}

Reflesh:
	IfWinNotExist, ahk_class %class%
	{
		class =
		flag = 0
	}
	return

ExitSub:
	WinSet, Transparent, Off, ahk_class %class%
	WinSet, Topmost, Off, ahk_class %class%
	ExitApp

タスクリストっぽいの (2005/12/03)

どう見ても作りかけです。そしてヤル気減衰。

タスバーに表示されてるアプリのウィンドウタイトルを頭にindexつけてリストメニュー化 → 選択するとそのウィンドウがアクティブに。

WinGet, id, list, , , Program Manager
indexA := 0
Loop, %id%
{
	StringTrimRight, this_id, id%a_index%, 0
	WinGetTitle, this_title, ahk_id %this_id%
	WinGetClass, this_class, ahk_id %this_id%
	If (this_title ="" || this_class = "TApplication")	;空ウィンドウ潰し
		Continue
	else
		indexA += 1
		Menu, task_list, Add, &%indexA% %this_title%, Activate_Window
;		Menu, sub1, Add, Close, Close_Window
;		Menu, task_list, Add, &%indexA% %this_title%, :sub1

}
Menu, task_list, Show
return

Activate_Window:
	wtitle = %A_ThisMenuItem%
	StringGetPos, spacePos, wtitle, %A_Space%
	spacePos += 1
	StringTrimLeft, wtitle, wtitle, spacePos
	WinActivate, %wtitle%
	return

Close_Window:
	MsgBox, Close!
	return

普通に WinGet?, id, list, , , Program Manager しただけだと、どっから来たのかよく分からない有象無象の空のウィンドウやDelphi製のアプリに存在する"TApplication"っていうウィンドウクラスの空ウィンドウも検出されちゃうので、If (this_title ="" || this_class = "TApplication") でそれらを潰した。

ダウンロード時に保存先ディレクトリをポップアップメニューで振り分ける

D:\Picture 以下に manko, tinko, unko というディレクトリが置かれている場合 (D:\Picture\manko, D:\Picture\tinko, D:\Picture\unko) の 動作風景

ダウンロードエンジンは WGET に頼りきり。

;----------------------------------------------------------------------------------------------------
; ShuffleDown.ahk (2005/10/20) - ダウンロード時に保存先ディレクトリをポップアップメニューで振り分け
;----------------------------------------------------------------------------------------------------

; このスクリプトの第一パラメータとしてダウンロードしたいファイルのURLを渡す。
; 指定親ディレクトリ内のディレクトリをポップアップメニュー形式でリスト表示。(サブディレクトリ含まず)
; 選択したディレクトリに先ほど渡されたURLのファイルをダウンロードしてくる。(WGETを使用)
; "MakeDir" を選択するとInputBoxが出てくるのでそこに新規作成したいディレクトリ名を。作成と同時に、先ほど渡されたURLのファイルをそこへダウンロード。


pDir = D:\Picture\	;振り分けたいディレクトリ群がある親ディレクトリ
wget = D:\App\wget\bin\wget.exe	;wgetの絶対パス

url = %1%
wget_opt = -c --referer=%url%	;wgetのオプション(-P以外)

If url =
{
	MsgBox, (´・ω・``) 引数あらへんがな
	return
}
else
{
	Loop, %pDir%*, 2, 0
	{
		Menu, DownDir, Add, &%A_LoopFileName%, DownHere
	}
	Menu, DownDir, Add
	Menu, DownDir, Add, &MakeDir, MakeDir_Down
	Menu, DownDir, Show
	return
	}

DownHere:
	StringTrimLeft, dDir, A_ThisMenuItem, 1
	Run, %wget% %wget_opt% -P %pDir%%dDir% %url%
	return

MakeDir_Down:
	InputBox, NewDir, 新規ディレクトリ名, , , 180, 90
	If ErrorLevel <> 0
		return
	FileCreateDir, %pDir%%NewDir%
	Run, %wget% %wget_opt% -P %pDir%%NewDir% %url%
	return

Syleraの画像上右クリックメニューに PassImageUri? して組み込んで使ってる。

リファラーがターゲットURLそのまんまなんでたまにリファラチェックで弾かれるかも。
サブディレクトリを作ったりそこへ保存したりする機能はカット。

指定したウインドウがダイアログかどうかを調べる関数 「フォルダの参照」対応版

猫歩き - AutoHotKey/Script/Dialog便利化スクリプト にある「ダイアログを呼び出したソフトによってデフォルトのフォルダを設定するスクリプト」 の isDialog関数 を「フォルダの参照」ダイアログにも対応させたもの。

isDialog(window="")
{
	if window =
		window = A
	DetectHiddenText, On
	WinGetClass, class, %window%
	ControlGetText, label, static3, %window%
	WinGetTitle, title, %window%
	if(class = "#32770" && ((label = "ファイル名(&N):" || label = "フォルダ:") || title = "フォルダの参照"))
		return true
	else
		return false
}

WinGetTitle?, title, %window% と title = "フォルダの参照" 追加しただけ。

キーボードからタスクトレイを操作する。

全然効かないアプリがあったりする。変な誤爆も多い。

;===== TrayControl.ahk - キーボードからタスクトレイを操作する。 =====

; 元ネタ : WSH/タスクトレイをアクティブに - Fioの素敵な日々 (http://kajika.tk/fio/?WSH%2F%A5%BF%A5%B9%A5%AF%A5%C8%A5%EC%A5%A4%A4%F2%A5%A2%A5%AF%A5%C6%A5%A3%A5%D6%A4%CB)

; →↓←↑ : フォーカス移動
; Shift+Enter : シングルクリック (Space)
; Enter : ダブルクリック (Enter)
; Application Key :  メニュー表示 (Shift+F10)

Send, #{TAB}	; "Win+Tab"でタスクバーにフォーカス移動
Send, {TAB 3}	; "Tab" 3回でタスクトレイにフォーカス移動(クイック起動使用時)
Send, {RIGHT}	; AHKアイコンを回避

+Enter:: 
	Send, {SPACE}
	ExitApp

~Enter:: ExitApp

~AppsKey:: 
	Send, +F10
	ExitApp

~ESC:: ExitApp

後で気づいた。タスクトイレにフォーカス移すには "Win+B" の方が簡単でいい。

任意のウィンドウを常に最前面表示し、マウスオーバー時に隠す。

動画観ながら他の作業やるときに便利かな。
以下のスクリプトは、対象となるウィンドウが DV のものの場合。

;--------------------------------------------------------------------------
; OnTopOverHide.ahk - 任意のウィンドウを常に最前面。マウスオーバーで隠す。 
;--------------------------------------------------------------------------

; Last Modified : 05/10/21

#Persistent
#WinActivateForce

class =ahk_class TForm_DV	;対象ウィンドウのウィンドウクラス名

WinGetActiveTitle, lastATitle

WinGetPos, x, y, w, h, %class%
WinActivate, %class%
WinSet, AlwaysOnTop, ON, %class%
WinActivate, %lastATitle%

x1 := x + w
y1 := y + h
;y += 25	;タイトルバーをマウスオーバー判定から除く。

flag = 0

SetTimer, OverHide, 100	;100ms毎にマウス位置をチェックし、ウィンドウを隠すか判断。
return

OverHide:
	IfWinNotExist, %class%	;対象ウィンドウがなくなってれば即終了。
		ExitApp
	CoordMode,Mouse,Screen
	MouseGetPos, xPos, yPos
	If xPos between %x% and %x1%
		If yPos between %y% and %y1%
		{
			WinSet, AlwaysOnTop, OFF, %class%
			WinSet, Bottom, , %class%
			flag = 1
		}
		else
			gosub RestoreOnTop
	else
		gosub RestoreOnTop
	return

RestoreOnTop:
	If flag = 1
	{
		WinGetActiveTitle, lastATitle
		WinActivate, %class%
		WinSet, AlwaysOnTop, ON, %class%
		WinActivate, %lastATitle%
		flag = 0
	}
	return

;[Win]+[F10]で"Pause"
#F10::  
	WinSet, AlwaysOnTop, OFF, %class%
	Pause, Toggle
	return
;[Win]+[F11]で"Pause"解除。 
#F11::  
	Pause, Toggle
	WinActivate, %class%
	WinSet, AlwaysOnTop, ON, %class%
	return
;[Win]+[F12]で終了。
#F12::
	WinSet, AlwaysOnTop, OFF, %class%
	ExitApp
	return

「タイトルバーをマウスオーバー判定から除く。」といちいちPauseかけたりせんでも[閉じる]ボタン押しにいけてええんやけど、ちょうどその下に操作したい箇所があった場合は邪魔になるので。
あと、このスクリプトだとスクリプト起動時に対象ウィンドウの位置を取得してるから、対象ウィンドウを移動させた場合にマウスオーバー判定が狂う。

動画・音楽に関してファイル情報によって開くアプリを振り分ける。

マルチメディアファイルの情報取得には、真空波動研SuperLite を使用。んで、クリップボードの中から引き出す。

;Avi WMV9 Filter 050907

#NoTrayIcon

paraLen = %0%
Loop,%paraLen%
{
  buf := %a_index%
  arg = %arg% %buf%
}
arg = "%arg%"

RunWait, C:\App\sinkusuperlite\SinkuSuperLite.exe /s %arg%
IfInString, clipboard,  Windows Media Video 9	;"WMV9"かどうかで振り分け
{
	Run, C:\App\DV\dv.exe %arg%
	return
}
else
{
	Run, C:\App\MPlayer-KK\mplayer.exe %arg%
	return
}

12行目のところをいろいろ変えることで、fpsや画面サイズなんかで振り分けて楽しむことが出来る。

ディレクトリに一個ずつ入ったファイル(ファイル名重複あり)を大量に一個上の階層にageる。

; --- FlatDir.ahk ---
paraLen = %0%
Loop, %paraLen%
{
	sDir = %a_index%
	SplitPath, %sDir%, cDN, pDir
	FileMove, %pDir%\%cDN%\*.*, %pDir%\*.*
	If ErrorLevel <> 0 
		FileMove, %pDir%\%cDN%\*.*, %pDir%\*_%a_index%.*
	FileRemoveDir, %pDir%\%cDN%
}

動作例

D:\unko\manko\000.png
D:\unko\manks\000.png
D:\unko\mange\001.png
↓
D:\unko\000.png
D:\unko\000_2.png
D:\unko\001.png

上の例の場合だと、引数として

D:\unko\manko D:\unko\manks D:\unko\mange

を渡す。

ファイル名が被ってた場合はディレクトリ内のファイル全部をリネームしようとするんで、ディレクトリに複数ファイルが入ってた場合は、別にリネームする必要のないファイルもリネームされちゃう。まぁ今回はディレクトリに1個ずつしかないからこれでいいや。
ちなみに、リネーム法は拡張子除いたファイル名のケツに "_ループ回数" をつけてるだけ。

bmapを用いた画像振り分け

iswitchw2 のパクリ。

振り分けたい画像が詰まったディレクトリを第1引数にして発動。
そのディレクトリ内の1枚目(名前降順)の画像をbmapが開いて起動。直後、インプットボックスつきの小さなリストウィンドウが最前面に現れる。初期段階では、pDir 直下のディレクトリ名が列挙されているので、インプットボックスからインクリメンタルサーチで振り分けたいディレクトリを絞っていく。リスト上でそのディレクトリ名を選択した状態で"Enter"すると、そこへbmapで表示中の画像ファイルが"Move"され、次の画像へ移る。
"Delete"した場合は問答無用で削除。
"PageUp?", "PageDown?" は、今表示してる画像の処理は保留して、それぞれ「一つ前」「一つ後」のファイルへ移る。
"Esc" で、bmapとImgClassify?のメインウィンドウを閉じる。
1周回ったかどうかの判定は自動でやらんので、また同じの出てきたなとかエラー出まくりんぐになったら、手動で終了。
対応形式は、bmap準拠なんで大概いける。と言いつつ、拡張子が "jpeg" のように4文字になってると駄目。

;----- Config -----

bmap = D:\app\g_view\bmap_wo\bmap.exe	;bmap.exeのフルパス。
pDir = D:\Picture\	;振り分け先候補ディレクトリ群の1つ上の親。
sDir = %1%\	;振り分けたい画像があるディレクトリ。この場合だと第1引数。
;sDir = D:\Download\Picture\


;----- Main -----

FunctionBmapStart()	;bmapで指定ディレクトリの1枚目の画像を開く
WinWait, ahk_class bmap, , 5	;早漏対策
	;メインウィンドウ位置を決める。
	WinGetPos, x, y, , , ahk_class bmap
	y += 22

;メインウィンドウ作成
GUI, Margin, 1, 1
GUI, Add, Edit, w100 r1 vInputBox,
GUI, Add, ListBox, w100 r10 vListBox
GUI, +ToolWindow
GUI, Show, X%x% Y%y%, ImgClassify

WinSet, AlwaysOnTop, ON, ImgClassify	;メインウィンドウを常に最善面

gosub Reset

SetTimer, Main, 360
return


;----- Subroutine -----

Main:
	Main()
	return

Reset:
	RefreshList("")
	ControlSetText, Edit1, , ImgClassify
	return


;----- Function -----

Main()
{
	static oldInputStr
	t := GetInputStr()
	if oldInputStr <> %t%
	{
		oldInputStr := t
		i := RefreshList(t)
		if i = 1
		{
			FunctionMove()
		}
	}
	return
}

RefreshList(Word)
{
	global pDir
	pDirNum = 0
	Loop, %pDir%*, 2
	{
		pDir%A_Index% = %A_LoopFileName%
		pDirNum++
	}
	Loop, %pDirNum%
	{
		d := pDir%A_Index%
		ifInString, d, %Word%
		{
			StringGetPos, p, d, %Word%
			if p = 0
			{
				List = %List%%d%|
				pDirNum++
			}
		}
	}
	GUIControl, ,ListBox,
	GUIControl, ,ListBox, |%List%
	GUIControl, Choose, ListBox, 1
	return pDirNum
}

GetInputStr()
{
	GUIControlGet, t, ,InputBox
	return t
}

GetSourcePath()
{
	global sDir
	WinGetTitle, title, ahk_class bmap
	StringGetPos, cutPos, title, ., R1
	cutPos +=4
	StringLeft, fName, title, %cutPos%
	sPath = %sDir%%fName%
	return sPath
}

FunctionMove()
{
	global pDir
	GUIControlGet, Item, , ListBox
	dDirPath = %Item%
	sPath := GetSourcePath()
	FileMove, %sPath%, %pDir%%dDirPath%\
}

FunctionBmapStart()
{
	global sDir, bmap
	Loop, %sDir%*.*
	{
		sFile = %A_LoopFileFullPath%
		break
	}
	Run, %bmap% %sFile%
}


;----- HotKey & GUI Event -----

~Down::
	IfWinNotActive, ImgClassify
	{
		return
	}
	GUIControlGet, f, Focus
	if f = Edit1
	{
		GUIControl, Focus, ListBox
		send, {Down}
		GUIControl, Focus, InputBox
	}
	return

~Up::
	IfWinNotActive, ImgClassify
	{
		return
	}
	GUIControlGet, f, Focus
	if f = Edit1
	{
		GUIControl, Focus, ListBox
		send, {Up}
		GUIControl, Focus, InputBox
	}
	return

~PgDn::
	IfWinNotActive, ImgClassify
	{
		return
	}
	PostMessage, 273, 32791, 0, , ahk_class bmap
	return

~PgUp::
	IfWinNotActive, ImgClassify
	{
		return
	}
	PostMessage, 273, 32792, 0, , ahk_class bmap
	return

~Del::
	IfWinNotActive, ImgClassify
	{
		return
	}
	sPath := GetSourcePath()
	FileDelete, %sPath%
	return

~Enter::
	IfWinNotActive, ImgClassify
	{
		return
	}
	FunctionMove()
	gosub Reset
	PostMessage, 273, 32791, 0, , ahk_class bmap
	return

GUIClose:
GUIEscape:
	WinClose, ahk_class bmap
	ExitApp

Incrementally Search - Picture Distributer を使った方がいい。

クリップボード内の文字列を、各行の先頭に任意の文字列を追加して置換

「半角スペース」を先頭に追加しようとすると、一行目だけ失敗する。

InputBox, add, , , , 130, 90, , , , , >

if ErrorLevel<>0
Exit
else
str = %clipboard%
Loop, Parse, str, `n
{
	if str_row =
		str_row = %add%%A_LoopField%
	else
		str_row = %str_row%`n%add%%A_LoopField%
}
clipboard = %str_row%
return

指定ファイルの階層を1層深くする。

ファイルパスが渡されると、同階層に新規ディレクトリを作成し、そこへファイルを放り込む。
その後、あふで新規ディレクトリの中身確認。

InputBox, c_dir, 新規ディレクトリ名, , , 180, 90
If ErrorLevel <> 0
return

path = %1%
SplitPath, path, , p_dir
dir = %p_dir%\%c_dir%
FileCreateDir, %dir%

paraLen = %0%
Loop, %paraLen%
{
	num := %a_index%
	path = %num%
	FileMove, %path%, %dir%\
}

Run, D:\AFX\afxcmd.exe -P"%dir%\"



Tip'sらしきもの

複数行コメント

http://lukewarm.s101.xrea.com/test/read.cgi/bbs/1095764510/112-115

/*
memo
memomemo
*/

ひとりFACK

タスクトレイ内(ウィンドウ非表示)のアプリが操作できないみたいなんですが。

DetectHiddenWindows, On

リロード   新規 編集 凍結 差分 添付 複製 改名   トップ 一覧 検索 最終更新 バックアップ   ヘルプ   最終更新のRSS
Last-modified: Sun, 21 Dec 2008 17:43:14 JST (1133d)