【コピペだけ】ADHDの過集中を防ぐ!時間になったらPCを強制ロックする秘密兵器(Win/Mac両対応)
「気づいたら夜中の2時まで作業していた…」
「やめなきゃいけないのに、キリがなくてダラダラ続けてしまう…」
タスクに集中しすぎて切り替えが難しくなる「過集中」は、ADHD気味の方や、仕事に熱中しやすいビジネスパーソンによくある悩みです。
そこで今回は、指定した時間になったらPCを強制的に画面ロックするタイマーを用意しました。
難しい設定は一切なし!コードをそのままコピペするだけで、あなた専用の「強制終了スイッチ」が作れます。
1. Windows版:指定時間にPCをロックするタイマー
Windowsの方は、以下のコードをコピーして使うだけで、デスクトップに見やすいタイマー画面が作れます。
使い方(3ステップ)
- デスクトップの何もないところで右クリック >「新規作成」>「テキスト ドキュメント」を作ります。
- 作ったファイルを開き、以下のコードを丸ごとコピー&ペーストします。
- ファイルの名前を
timer.txtからtimer.htaに変更します(拡張子を.htaにするのがポイントです)。
コピペ用コード(Windows用)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>強制ロックタイマー</title>
<style>
body {
font-family: 'Meiryo UI', sans-serif;
background-color: #f0f0f0;
padding: 20px;
font-size: 14px;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
input[type="text"] {
padding: 5px;
font-size: 16px;
width: 80px;
text-align: center;
}
button {
padding: 6px 15px;
font-size: 14px;
cursor: pointer;
margin-left: 10px;
}
#status {
margin-top: 20px;
color: #666;
min-height: 40px;
}
</style>
<script>
window.resizeTo(400, 280);
var timerId = null;
var targetTimeObj = null;
function setTimer() {
var timeStr = document.getElementById("timeInput").value;
var timeParts = timeStr.split(":");
if (timeParts.length !== 2 || isNaN(timeParts[0]) || isNaN(timeParts[1])) {
alert("時間の形式が正しくありません。
「18:30」のように半角で入力してください。");
return;
}
var now = new Date();
targetTimeObj = new Date(now.getFullYear(), now.getMonth(), now.getDate(), parseInt(timeParts[0], 10), parseInt(timeParts[1], 10), 0);
if (targetTimeObj <= now) {
targetTimeObj.setDate(targetTimeObj.getDate() + 1);
}
var formattedTime = targetTimeObj.getFullYear() + "/" +
('0' + (targetTimeObj.getMonth() + 1)).slice(-2) + "/" +
('0' + targetTimeObj.getDate()).slice(-2) + " " +
('0' + targetTimeObj.getHours()).slice(-2) + ":" +
('0' + targetTimeObj.getMinutes()).slice(-2) + ":00";
document.getElementById("status").innerHTML = formattedTime + " にロックします。<br>※この画面は最小化して作業を続けてください。";
document.getElementById("btnSet").disabled = true;
document.getElementById("timeInput").disabled = true;
document.getElementById("btnCancel").disabled = false;
timerId = setInterval(checkTime, 1000);
}
function cancelTimer() {
if (timerId !== null) {
clearInterval(timerId);
timerId = null;
}
document.getElementById("status").innerHTML = "タイマーをキャンセルしました。";
document.getElementById("btnSet").disabled = false;
document.getElementById("timeInput").disabled = false;
document.getElementById("btnCancel").disabled = true;
}
function checkTime() {
var now = new Date();
if (now >= targetTimeObj) {
clearInterval(timerId);
timerId = null;
document.getElementById("status").innerHTML = "ロックを実行しました。";
document.getElementById("btnSet").disabled = false;
document.getElementById("timeInput").disabled = false;
document.getElementById("btnCancel").disabled = true;
try {
var shell = new ActiveXObject("WScript.Shell");
shell.Run("rundll32.exe user32.dll,LockWorkStation", 0, false);
} catch (e) {
alert("ロックの実行に失敗しました。セキュリティ設定を確認してください。");
}
}
}
</script>
</head>
<body>
<div class="container">
<input type="text" id="timeInput" value="18:30">
<button id="btnSet" onclick="setTimer()">セット</button>
<button id="btnCancel" onclick="cancelTimer()" disabled>キャンセル</button>
<div id="status">時間を入力して「セット」を押してください。</div>
</div>
</body>
</html>
2. Mac版:「ショートカット」で指定時間に画面を暗転させるタイマー
Macユーザーの方は、標準アプリの「ショートカット(Shortcuts)」を使うことで、同様の強制ロックタイマーを作成できます。
使い方(3ステップ)
- Macの「ショートカット」アプリを開き、画面上部の「+」ボタンを押して新しいショートカットを作成します。
- 右側の「アクションを検索」欄に「AppleScript」と入力し、「AppleScriptを実行」を中央のエリアにドラッグ&ドロップします。
- 最初から入っているコード(
on run...などの文字)をすべて消去し、以下のコードを丸ごとコピペして保存します。
コピペ用コード(Mac用)
on run {input, parameters}
-- ① 時刻を入力する画面
set timeInput to display dialog "ロックする時刻を半角で入力してください。" & return & "(例: 18:30)" default answer "18:30" buttons {"キャンセル", "セット"} default button "セット"
set timeStr to text returned of timeInput
-- ② 時間の分解とエラーチェック
set AppleScript's text item delimiters to ":"
try
set timeParts to text items of timeStr
set targetHour to item 1 of timeParts as integer
set targetMin to item 2 of timeParts as integer
on error
display dialog "時間の形式が正しくありません。「18:30」のように半角で入力してください。" buttons {"OK"} default button "OK" with icon stop
error number -128
end try
-- ③ ターゲット時刻の計算
set now to current date
set targetTime to current date
set hours of targetTime to targetHour
set minutes of targetTime to targetMin
set seconds of targetTime to 0
if targetTime ≤ now then
set targetTime to targetTime + (1 * days)
end if
-- ④ 残り時間を計算
set diffSeconds to targetTime - now
-- ⑤ 指定時間まで待機(ポップアップが出たままになります)
display dialog timeStr & " に画面をロックします。" & return & "このまま画面を開いたままにして作業を続けてください。" buttons {"キャンセル"} default button "キャンセル" giving up after diffSeconds
-- ⑥ 時間が経過したらディスプレイをスリープ(ロック状態へ)
do shell script "pmset displaysleepnow"
return input
end run
💡 なぜこの「強制ロック」が効果的なのか?
スマホのアラームや普通のタイマーだと、鳴っても「あと5分…」と延長してしまいがちですよね。
このスクリプトの最大の強みは、「自分の意志に関係なく、強制的に画面がパッと消える(ロックされる)」という点です。
- 作業の熱が強制的に冷めるので、ハッと現実に戻れる
- 「あと少し」ができない仕組みなので、諦めて休憩や退勤ができる
- データが消えるわけではなく、ただロックされるだけなので安心
過集中を自分の意志で止めるのは至難の業です。ぜひこの「コピペタイマー」を使って、テクノロジーの力で強制的に作業を切り替えてみてください!
(English Version)
[Just Copy & Paste] Prevent ADHD Hyperfocus! A Secret Weapon to Force-Lock Your PC at a Set Time (Win & Mac)
“I realized it’s already 2 AM…”
“I know I need to stop, but I just keep going without a break…”
“Hyperfocus”—becoming so engrossed in a task that switching to something else feels nearly impossible—is a common challenge for those with ADHD traits or highly dedicated professionals.
To solve this, here is a forced-lock timer that automatically locks your PC screen at a designated time.
No complex settings required! Just copy and paste the code below to create your own “emergency shut-off switch.”
1. Windows Version: Lock PC at a Specific Time
For Windows users, you can create a clean, compact timer on your desktop just by using the code below.
How to Use (3 Steps)
- Right-click an empty space on your desktop > select “New” > Click “Text Document.”
- Open the file and copy and paste the entire code provided below.
- Rename the file from
timer.txttotimer.hta(changing the extension to.htais the key step).
Code to Copy (For Windows)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Forced Lock Timer</title>
<style>
body {
font-family: 'Meiryo UI', sans-serif;
background-color: #f0f0f0;
padding: 20px;
font-size: 14px;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
input[type="text"] {
padding: 5px;
font-size: 16px;
width: 80px;
text-align: center;
}
button {
padding: 6px 15px;
font-size: 14px;
cursor: pointer;
margin-left: 10px;
}
#status {
margin-top: 20px;
color: #666;
min-height: 40px;
}
</style>
<script>
window.resizeTo(400, 280);
var timerId = null;
var targetTimeObj = null;
function setTimer() {
var timeStr = document.getElementById("timeInput").value;
var timeParts = timeStr.split(":");
if (timeParts.length !== 2 || isNaN(timeParts[0]) || isNaN(timeParts[1])) {
alert("Invalid time format.
Please enter like '18:30' using half-width characters.");
return;
}
var now = new Date();
targetTimeObj = new Date(now.getFullYear(), now.getMonth(), now.getDate(), parseInt(timeParts[0], 10), parseInt(timeParts[1], 10), 0);
if (targetTimeObj <= now) {
targetTimeObj.setDate(targetTimeObj.getDate() + 1);
}
var formattedTime = targetTimeObj.getFullYear() + "/" +
('0' + (targetTimeObj.getMonth() + 1)).slice(-2) + "/" +
('0' + targetTimeObj.getDate()).slice(-2) + " " +
('0' + targetTimeObj.getHours()).slice(-2) + ":" +
('0' + targetTimeObj.getMinutes()).slice(-2) + ":00";
document.getElementById("status").innerHTML = "Will lock at " + formattedTime + ".<br>※Minimize this window and continue your work.";
document.getElementById("btnSet").disabled = true;
document.getElementById("timeInput").disabled = true;
document.getElementById("btnCancel").disabled = false;
timerId = setInterval(checkTime, 1000);
}
function cancelTimer() {
if (timerId !== null) {
clearInterval(timerId);
timerId = null;
}
document.getElementById("status").innerHTML = "Timer canceled.";
document.getElementById("btnSet").disabled = false;
document.getElementById("timeInput").disabled = false;
document.getElementById("btnCancel").disabled = true;
}
function checkTime() {
var now = new Date();
if (now >= targetTimeObj) {
clearInterval(timerId);
timerId = null;
document.getElementById("status").innerHTML = "Lock executed.";
document.getElementById("btnSet").disabled = false;
document.getElementById("timeInput").disabled = false;
document.getElementById("btnCancel").disabled = true;
try {
var shell = new ActiveXObject("WScript.Shell");
shell.Run("rundll32.exe user32.dll,LockWorkStation", 0, false);
} catch (e) {
alert("Failed to execute lock. Please check your security settings.");
}
}
}
</script>
</head>
<body>
<div class="container">
<input type="text" id="timeInput" value="18:30">
<button id="btnSet" onclick="setTimer()">Set</button>
<button id="btnCancel" onclick="cancelTimer()" disabled>Cancel</button>
<div id="status">Enter time and press "Set".</div>
</div>
</body>
</html>
2. Mac Version: Turn Off Screen via the “Shortcuts” App
Mac users can achieve the same forced-lock mechanism using the default “Shortcuts” app.
How to Use (3 Steps)
- Open the “Shortcuts” app on your Mac, and click the “+” button at the top to create a new shortcut.
- In the “Search for actions” bar on the right side, type “AppleScript“, then drag and drop “Run AppleScript” into the central workspace.
- Delete all the placeholder text (such as
on run...) and copy and paste the entire script below.
Code to Copy (For Mac Shortcuts)
on run {input, parameters}
-- ① Input Time Window
set timeInput to display dialog "Enter the lock time in 24h format:" & return & "(e.g., 18:30)" default answer "18:30" buttons {"Cancel", "Set"} default button "Set"
set timeStr to text returned of timeInput
-- ② Time Breakdown & Error Checking
set AppleScript's text item delimiters to ":"
try
set timeParts to text items of timeStr
set targetHour to item 1 of timeParts as integer
set targetMin to item 2 of timeParts as integer
on error
display dialog "Invalid format. Please use '18:30'." buttons {"OK"} default button "OK" with icon stop
error number -128
end try
-- ③ Calculate Target Time
set now to current date
set targetTime to current date
set hours of targetTime to targetHour
set minutes of targetTime to targetMin
set seconds of targetTime to 0
if targetTime ≤ now then
set targetTime to targetTime + (1 * days)
end if
-- ④ Calculate Remaining Time
set diffSeconds to targetTime - now
-- ⑤ Wait Until Specified Time (Popup stays open)
display dialog "Screen will lock at " & timeStr & "." & return & "Keep this prompt open and continue your work." buttons {"Cancel"} default button "Cancel" giving up after diffSeconds
-- ⑥ Sleep Display (Triggers Lock Screen)
do shell script "pmset displaysleepnow"
return input
end run
💡 Why is this “Forced Lock” so effective?
With regular phone alarms or standard timers, it is too easy to hit snooze and think, “Just 5 more minutes…”
The greatest advantage of these scripts is that they take your willpower out of the equation. The screen just blacks out and locks completely.
- It forcefully snaps you out of your hyperfocused state, bringing you back to reality.
- Since it doesn’t give you a choice to delay, it naturally pushes you to take a break or finish work.
- It safely locks the workstation without losing any unsaved background data.
Stopping hyperfocus with pure willpower is incredibly hard. Leverage the power of technology with this simple copy-and-paste timer to stay on track!


コメント