[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(DTPtechNote:1635) Re: [InDesign CS3][scripting]Event scripting



流星さんの
>作業日報(ウチでは物件毎に何時から何時まで)を
こんな感じ、、、なんだと思う。ASですが^^
#というか、まだよくわかってないです。

「start_log.applescript」と「stop_log.applescript」のエイリアスは「Scripts Panel」フォルダに入れてください。「write_log.applescript」はこれらのスクリプトと同じ階層に置いてください。
start_log.applescriptでログ開始で、stop_log.applescriptでログ停止です。



---------------------------------------------start_log.applescriptここから
tell application "Adobe InDesign CS3"
	set my_folder to my get_folder_path()
	set handler_sctipt to "write_log.applescript" --ハンドラとなるスクリプト
	
	--新規ドキュメント
	make event listener with properties {event type:"afterNew", handler:my_folder & handler_sctipt, captures:false}
	--ドキュメントを開く
	make event listener with properties {event type:"afterOpen", handler:my_folder & handler_sctipt, captures:false}
	--ドキュメントを閉じる
	make event listener with properties {event type:"beforeClose", handler:my_folder & handler_sctipt, captures:false}
	
end tell


--このスクリプトの入っているフォルダパスを返す
--このスクリプト(またはエイリアス)が「Scripts Panel」フォルダまたは「Startup Scripts」フォルダに入っていないと無効
to get_folder_path()
	tell application "Adobe InDesign CS3"
		set my_script to active script
		tell application "Finder"
			set my_file to file my_script
			return (container of my_file) as Unicode text
		end tell
	end tell
end get_folder_path
---------------------------------------------start_log.applescriptここまで


---------------------------------------------stop_log.applescriptここから
tell application "Adobe InDesign CS3"
	set my_folder to my get_folder_path()
	set handler_sctipt to "write_log.applescript" --ハンドラとなるスクリプト
	
	remove event listener event type "afterNew" handler file (my_folder & handler_sctipt) without captures
	remove event listener event type "afterOpen" handler file (my_folder & handler_sctipt) without captures
	remove event listener event type "beforeClose" handler file (my_folder & handler_sctipt) without captures
end tell

to get_folder_path()
	tell application "Adobe InDesign CS3"
		set my_script to active script
		tell application "Finder"
			set my_file to file my_script
			return (container of my_file) as Unicode text
		end tell
	end tell
end get_folder_path
---------------------------------------------stop_log.applescriptここまで


---------------------------------------------write_log.applescriptここから
--書き込み部分は変えないとまずいかも

tell application "Adobe InDesign CS3"
	try
		set doc_name to (name of document 1) as Unicode text
		set my_log to my get_folder_path() & "log.txt"
		--set tmp_str to "" as Unicode text
		
		set my_event to evt
		set tmp_str to ((time stamp of my_event) as Unicode text) & tab & doc_name & return
		--set tmp_str to tab & tmp_str & doc_name & return
		
		my write_file(tmp_str, my_log)
	end try
end tell

to get_folder_path()
	tell application "Adobe InDesign CS3"
		set my_script to active script
		tell application "Finder"
			set my_file to file my_script
			return (container of my_file) as Unicode text
		end tell
	end tell
end get_folder_path

-----★ファイル書き出し(追記)
to write_file(str, my_file)
	tell application "Finder"
		set FH to open for access my_file with write permission
		try
			--set eof FH to 0
			--write ((ASCII character 254) & (ASCII character 255)) to FH --BOMを書き込む
			write str to FH starting at -1 as Unicode text
			--write str to FH
		on error errMsg number errNo
			close access FH
			my my_error("書き込み時のエラーです" & return & errMsg & errNo, true)
		end try
		close access FH
		--update my_file
	end tell
end write_file

---------------------------------------------write_log.applescriptここから