Clip Collector for MacMac 剪貼簿收集器

Data entry often means copying one value, switching to a spreadsheet, pasting it into the next cell and switching back. This small script removes the pasting. Leave it running and keep copying: every piece of text you copy is added to one file on your Desktop, ready for an AI assistant to arrange into a table.

做資料輸入時,往往要複製一項資料、切換到試算表、貼到下一格,再切換回來。這個小腳本省去貼上的步驟:讓它在背景運行,你只需要不停複製,每次複製的文字都會自動加進桌面上的同一個檔案,之後交給 AI 整理成表格。

It needs only TextEdit and Terminal, which come with every Mac. Setup takes about five minutes and is done once.

只需要每部 Mac 都內置的「文字編輯」和「終端機」。設定約需五分鐘,只做一次。

Works on 適用
macOS
Setup 設定時間
About 5 minutes
Saves to 儲存位置
~/Desktop/clips.txt
Data sent online 上傳資料
None

Set it up設定步驟

  1. Create the script建立腳本

    Open TextEdit and click New Document. In the menu bar, choose Format → Make Plain Text. If the menu shows Make Rich Text instead, the document is already plain text. Paste the script below.

    打開「文字編輯」(TextEdit),按 New Document 新增文件。在選單列選擇 Format → Make Plain Text;如果選單顯示的是 Make Rich Text,即代表文件已是純文字。然後貼上以下腳本。

    clip-collector.command
    #!/bin/bash
    # Clip Collector: appends every new piece of copied text to clips.txt
    f=~/Desktop/clips.txt
    
    # Mark the start of each session with a timestamp
    printf '\n===== %s =====\n' "$(date '+%Y-%m-%d %H:%M:%S')" >> "$f"
    
    old=$(pbpaste)
    echo "Recording clipboard... press Control+C to stop"
    
    while true; do
      new=$(pbpaste)
      if [ "$new" != "$old" ]; then
        printf '%s\n---\n' "$new" >> "$f"
        old="$new"
      fi
      sleep 0.5
    done
  2. Save it as a .command file儲存為 .command 檔案

    Press Command+S. Name the file clip-collector.command and save it to Desktop. If macOS asks whether to use .txt, choose Use .command.

    按 Command+S,檔名填 clip-collector.command,存到 Desktop(桌面)。如果系統問你是否改用 .txt,選 Use .command。

  3. Let Terminal use your Desktop允許終端機存取桌面

    macOS keeps Terminal out of the Desktop folder by default. Without this step, the next one fails with Operation not permitted. Open System Settings → Privacy & Security → Files & Folders, find Terminal and turn on Desktop Folder.

    macOS 預設不讓終端機存取桌面,不做這一步,下一步會出現 Operation not permitted。打開 System Settings → Privacy & Security → Files & Folders,找到 Terminal,開啟 Desktop Folder。

    If Terminal is not listed, open Full Disk Access on the same page, click + and add Applications → Utilities → Terminal. Then quit Terminal with Command+Q and open it again.

    如果列表沒有 Terminal,在同一頁打開 Full Disk Access,按 + 加入 Applications → Utilities → Terminal。之後按 Command+Q 完全結束終端機,再重新打開。

  4. Make the file runnable讓檔案可以執行

    Open Terminal, paste this line and press Return. Nothing will be printed; that means it worked.

    打開終端機,貼上這一行並按 Return。終端機不會顯示任何內容,這就代表成功了。

    Terminal
    chmod +x ~/Desktop/clip-collector.command
  5. Double-click to start按兩下開始記錄

    Double-click clip-collector.command on your Desktop. A Terminal window opens and shows Recording clipboard…. It is now collecting.

    在桌面按兩下 clip-collector.command,會打開一個終端機視窗並顯示 Recording clipboard…,即表示已開始記錄。

    The first time, macOS may say it cannot verify the developer. Right-click the file, choose Open, then click Open again. It will not ask after that.

    第一次打開時,系統可能提示無法驗證開發者。請按右鍵選擇 Open,再按 Open 確認,之後便不會再問。

Use it使用方法

  • Copy with Command+C as usual. Within half a second, the text is added to clips.txt, with --- between entries.

    照常用 Command+C 複製,半秒內文字便會加進 clips.txt,每條之間以 --- 分隔。

  • Open the file at any time to check it. TextEdit may not refresh on its own, so close and reopen it to see new entries.

    記錄期間隨時可以打開檔案查看。「文字編輯」未必會自動更新內容,關掉再打開便能看到最新記錄。

  • To stop, click the Terminal window and press Control+C, then Command+W to close it.

    要停止時,先點一下終端機視窗,按 Control+C,再按 Command+W 關閉。

  • Each start adds a timestamp line, so separate sessions stay easy to tell apart.

    每次啟動都會先寫入一行時間戳記,方便分辨不同次的記錄。

Here is a sample file from two sessions of copying supermarket milk prices.

以下是分兩次複製超市牛奶價格後的檔案示例。

clips.txt
===== 2026-10-25 03:12:48 =====
Devondale Full Cream Milk | 2L
---
$4.20
---
Coles Dairy Full Cream Milk | 1L
---
$1.75
---
Pura Full Cream Milk | 2L
---
$4.65
---

===== 2026-10-25 03:24:13 =====
Dairy Farmers The Complete Dairy High Protein Full Cream Milk | 1L
---
$3.80
---
Gippsland Jersey Full Cream Milk | 2L
---
$6.20
---

Turn it into a table交給 AI 整理成表格

Copy fields in the same order every time, such as name and then price. Give the file to an AI assistant with a short instruction like the one below, and list the columns you need.

每次都按相同次序複製欄位,例如先名稱、後價格。把檔案交給 AI 時,附上類似下面的簡短指示,並寫上你需要的欄位。指示用中文寫也可以。

Instruction for the AI
Entries in this file are separated by ---. Lines starting with ===== mark when a session started. Arrange the entries into a table, one row per record, with these columns: [your columns].
Result
ProductSizePrice
Devondale Full Cream Milk2L$4.20
Coles Dairy Full Cream Milk1L$1.75
Pura Full Cream Milk2L$4.65
Dairy Farmers The Complete Dairy High Protein Full Cream Milk1L$3.80
Gippsland Jersey Full Cream Milk2L$6.20

Good to know 注意事項

  1. While it runs, everything you copy is saved, including passwords and verification codes. Stop it when you finish, and remove anything sensitive from the file.

    腳本運行期間,你複製的所有內容都會被記錄,包括密碼和驗證碼。用完請立即停止,並刪除檔案中的敏感內容。

  2. Only text is recorded. Copied images and files are skipped.

    只會記錄文字,複製的圖片和檔案不會被記錄。

  3. Copying the same text twice in a row records it once. If two fields in a row share a value, copy something else in between, or tell the AI how many fields each row has.

    連續兩次複製相同文字,只會記錄一次。如果相鄰兩個欄位的值一樣,可以在中間先複製別的內容,或告訴 AI 每行有幾個欄位。

  4. New sessions are added to the end of the same file. Delete clips.txt when a job is done; the script creates a new one next time. To keep a set, rename it, for example clips-milk-prices.txt. The script only writes to clips.txt.

    新的記錄會接在同一個檔案後面。完成一項工作後可以直接刪除 clips.txt,下次啟動時腳本會自動新建。想保留某一次的資料,可以把檔案改名,例如 clips-milk-prices.txt,腳本只會寫入 clips.txt。

  5. It works on any Mac. If you send the file to someone, they should repeat steps 3 to 5, because file transfers can remove the permission to run it.

    任何一部 Mac 都可以使用。如果把檔案傳給別人,對方需要重做第 3 至第 5 步,因為檔案經傳送後可能會失去執行權限。

How it works 運作原理

  1. Every half a second, the script reads the clipboard with pbpaste, a command built into macOS.

    腳本每半秒用 macOS 內置的 pbpaste 指令讀取一次剪貼簿。

  2. If the text differs from the last one it saw, the script adds it to the end of the file, followed by ---.

    如果內容與上一次不同,便加到檔案末端,並在後面加上 ---。

  3. Everything stays in a text file on your Mac. Nothing is sent anywhere.

    所有內容只保存在你 Mac 上的文字檔,不會上傳到任何地方。

This guide is for general information. Read any script before you run it on your computer. 本教學只供一般參考。在電腦上執行任何腳本前,請先閱讀其內容。