Skip to content

Instantly share code, notes, and snippets.

@scmx
Created January 23, 2023 10:48
Show Gist options
  • Save scmx/77b84b09ab797d901978b5e4ce61623e to your computer and use it in GitHub Desktop.
Save scmx/77b84b09ab797d901978b5e4ce61623e to your computer and use it in GitHub Desktop.
macOS Sequential Copy Paste pbcopy pbpaste shell script. Start it and copy some things. Press Ctrl+c and you get the list all things you copied. #macos #clipboard #sequential #paste #pbpaste #pbcopy #bash #shell

macOS Sequential Copy Paste pbcopy pbpaste shell script

Start it and copy some things, then press Ctrl+c and you get a list of all things you copied.

~/.bin/sequential-paste-recording

#!/usr/bin/env bash

list=()
last=""

echo "Starting sequential paste recording of clipboard copying"
echo "Press Ctrl+c when done, and all copied things will be returned"

on_exit() {
	echo "${#list[@]} clipboard copy calls recorded"
	echo
	for item in "${list[@]}"; do
		echo "$item"
	done
}

trap on_exit EXIT

pbcopy < /dev/null

while true; do
	now="$(pbpaste)"

	if [[ "$last" != "$now" ]]; then
		list+=("$now")
		last="$now"
		echo "Adding $now"
	fi

	sleep 0.1
done

chmod u+x ~/.bin/sequential-paste-recording

$ sequential-paste-recording
Starting sequential paste recording of clipboard copying
Press Ctrl+c when done, and all copied things will be returned
Adding foo
Adding bar
Adding baz
^C
3 clipboard copy calls recorded

foo
bar
baz

To try it I did

echo foo | pbcopy
echo bar | pbcopy
echo baz | pbcopy

This is an initial version. Could make it automatically put everythinig in clipboard while copying. But should probably try this simple variant first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment