自分の行動履歴を知りたい
自分の行動履歴を知りたい。
あの日何してたっけ?とかそういう時用。
概ねGoogleに把握されていると思うので、とりまGoogleの記録に関してはMap上の移動履歴系とブラウズ内容の検索、閲覧履歴等が参照できるようだ。
- タイムライン(移動履歴)
- Google - マイ アクティビティ(検索、閲覧等の履歴)
Mac上の作業履歴はコンソール.app
で各種ログを見ればある程度わかりそうだが色々あってどれを見ればいいのかよくわからない。
また、sysdiagnose
というコマンド(あるいは、ショートカットキーCommand-Option-Control-Shift-.
)で各種ログをTAR+GZ形式のファイルとして/var/tmp
ディレクトリに出力することもできるようだが、バグレポートを提出するときなどに使用されるようで、今回の目的には使用しづらい模様。
操作履歴を記録するソフトウェアもあるかもしれないが、わざわざそのようなソフトウェアを入れるのもなんだか憚られるので、AppleScriptでアクティブなアプリケーションを記録するアプリケーションを書いた。
しばらくはこれで様子を見ようかと思う。
アクティブなアプリケーションを記録するAppleScriptの例:
- デスクトップ上の
ActiveAppsHistory.log
ファイルに記録する。 - オプションの「ハンドラの実行後に終了しない」にチェックを入れて、アプリケーション形式で書き出す。
- 起動項目に入れるなどして、常時起動させておく。
property appName_previous : "" property appName : "" property logFileName : "ActiveAppsHistory.log" property lf : ASCII character 10 --改行コードをLFでテキスト作成用 set frontmostApp to path to frontmost application tell application "Finder" set appName_previous to name of frontmostApp end tell on idle set desktopPath to path to desktop as Unicode text set targetPath to desktopPath & logFileName set frontmostApp to path to frontmost application try tell application "Finder" set appName to name of frontmostApp end tell if (appName is not appName_previous) then set localTimeString to do shell script "date \"+%Y-%m-%d %H:%M:%S%z\"" --set info_to_write to localTimeString & " " & appName & return set info_to_write to localTimeString & " " & appName & lf --改行コードをLFに変更 my write_to_file(info_to_write, targetPath, true) set appName_previous to appName end if on error errStr number errorNumber set errorNumber_string to errorNumber as string --my sendMessageToNotification(my name, my name, errorNumber_string & return & errStr) my sendMessageToNotification(my name, my name, errorNumber_string & lf & errStr) --改行コードをLFに変更 --my sendMessageToNotification(my name, my name, errorNumber & return & errStr) --エラー出たので修正(2020-06-02) end try return 0.1 end idle on write_to_file(this_data, target_file, append_data) try set the target_file to the target_file as text set the open_target_file to open for access file target_file with write permission if append_data is false then set eof of the open_target_file to 0 --write this_data to the open_target_file starting at eof write this_data as «class utf8» to the open_target_file starting at eof --utf-8で書き込むように修正(2020-06-11) close access the open_target_file return true on error error_message try close access file target_file end try return error_message end try end write_to_file on sendMessageToNotification(TitleString, SubTitleString, MessageString) display notification MessageString with title TitleString subtitle SubTitleString sound name "Purr" end sendMessageToNotification
上記スクリプトの出力例:
2020-05-14 23:57:20+0900 Script Editor.app 2020-05-14 23:58:23+0900 Console.app
2020-06-02追記:
初出のコードだと
「{-15260, "
", "Finderはビジー状態です。"}のタイプをUnicode textに変換できません。(-1700)」
のようなエラーが出てダイアログに気づかないと記録が中断されていたので修正。
AppleScript では数値は自動的に Unicode text
に変換されないという感じだろうか。
2020-06-10追記:
「アプリケーションは実行されていません。(-600)」というエラーが出ることもある。どういうときに出るのかは不明。
2020-06-11追記:
テキストファイルを「文字コード:UTF-8、改行コード:LF」で書き出すように修正。
参考ページ:
- What’s your Mac been up to for the last 3 months? Inside macOS’s hidden activity records – The Eclectic Light Company
- 「sysdiagnose」でMacを知る - 新・OS X ハッキング!(225) | マイナビニュース
- dateコマンドで日付や時刻を表示したり設定する方法 | server-memo.net
- apex - Using Regex for YYY-MM-DD HH:MM:SS+/-TIMEZONE - Salesforce Stack Exchange
- Time zone - Wikipedia
- How To Format Date For Display or Use In a Shell Script - nixCraft