Skip to content

Instantly share code, notes, and snippets.

@arrowtype
Last active July 11, 2022 19:51
Show Gist options
  • Save arrowtype/c94fa89db8e24d5f1f8812d06e6c0844 to your computer and use it in GitHub Desktop.
Save arrowtype/c94fa89db8e24d5f1f8812d06e6c0844 to your computer and use it in GitHub Desktop.
A quick little command line tool to copy a left/right page count to your clipboard. Maybe helpful for book design.
"""
Book page cheat sheet!
Alternate left/right alongside number for a given page count.
Example:
1 Right
2 Left
3 Right
4 Left
5 Right
6 Left
7 Right
# etc
(Assumes you are on macOS. Might still work on Windows or Linux, etc, but this hasn’t been tested.)
USAGE:
1. Download this file
2. Select the file in Finder and then hit Command-Option-C to copy its path
2. Open the Terminal app
3. Paste the file path after "python3" in the terminal, like this:
python3 path_to_script/pagecount-cheatsheet.py
4. It will ask for a page count. Enter that number.
The cheat sheet will be copied to your clipboard!
Paste it into a note or whatever.
Note: If you have never before installed Python, macOS will prompt you to do so. Do that, restart Terminal, and try again.
"""
import math
import subprocess
def askPageCount():
try:
# prompt user for page count
total_pagecount = int(input("🤖 Enter a page count: "))
except:
# if user doesn't enter page count number, just use 32
total_pagecount = 32
return total_pagecount
def checkIfDivisibleBy16(total_pagecount):
# check if the pagecount is divisible by 16, and let the user know if not
if total_pagecount % 16 != 0:
lowerPossibility = math.floor(total_pagecount / 16) * 16
upperPossibility = math.ceil(total_pagecount / 16) * 16
print(f"⚠️ Psst: {total_pagecount} isn’t divisible by 16.")
print(f"⚠️ It won’t make even signatures.")
print(f"⚠️ Did you mean {lowerPossibility} or {upperPossibility}?")
def writePageCount(total_pagecount):
cheatSheet = []
for count in range(total_pagecount):
page = count + 1
# if page is odd
if page % 2 == 1:
cheatSheet.append(f"{page} Right")
# if page is even
else:
cheatSheet.append(f"{page} Left")
outputText = "\n".join(cheatSheet)
return outputText
def write_to_clipboard(output):
process = subprocess.Popen(
'pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE)
process.communicate(output.encode('utf-8'))
def main():
print() # print blank line
# ask user for a pagecount
total_pagecount = askPageCount()
print() # print blank line
# check if the pagecount is divisible by 16, and let the user know if not
checkIfDivisibleBy16(total_pagecount)
print() # print blank line
# create alternating number rows for cheat sheet
outputText = writePageCount(total_pagecount)
# write result to clipboard for easy use!
write_to_clipboard(outputText)
print(f"🤖 Cheat sheet copied to clipboard!")
print(f"🤖 Go paste it into a note or whatever.")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment