Skip to content

Instantly share code, notes, and snippets.

View dpinney's full-sized avatar

David Pinney dpinney

  • NRECA
  • Washington, DC
View GitHub Profile
@dpinney
dpinney / blinker.py
Created November 16, 2023 15:14
Slow Blink LED
#!/usr/local/bin/python
# Inspired by https://news.ycombinator.com/item?id=38274782#38276107
# Blinks a green circle on top of all windows at 60 BPM because it seems to help people focus?
# Requires `pip install pyqt5`
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QPixmap, QPainter, QColor, QBrush
from PyQt5.QtCore import QTimer, Qt
@dpinney
dpinney / convert_all_rtf_and_rtfd_to_docx.scpt
Created July 6, 2021 15:43
Convert all RTF and RTFD files to Word DOCX via AppleScript
# We do this with Pages because it's the only thing that can correctly convert rtfd.
# textutil works on rtf files with no text in them but not on rtfd.
set my_paths to {"/path/to/first/file.rtfd", "/path/to/second/file.rtfd"}
repeat with my_path in my_paths
tell application "Pages"
set my_file to (my_path as POSIX file)
set my_name to name of (info for my_file)
set doc to open my_file
export doc as Microsoft Word to alias (my_path & ".docx" as POSIX file)
@dpinney
dpinney / google_drive_download_link.py
Last active July 2, 2021 19:14
Convert Google Drive Share Link to Download Link
@dpinney
dpinney / tile all windows.sh
Created February 4, 2021 17:28
Tile all windows of all macOS applications (AppleScript)
#!/usr/bin/osascript
-- Get the size of the Display(s), only useful if there is one display
-- otherwise it will grab the total size of both displays
tell application "Finder"
set _b to bounds of window of desktop
set screen_width to item 3 of _b
set screen_height to item 4 of _b
end tell
@dpinney
dpinney / get_free_times_from_ical.py
Created January 9, 2021 21:35
Get all free times from iCal on the Command Line
'''
Get all free times from iCal.
Requirements:
brew install ical-buddy
pip install py-dateutil
Notes:
Run in terminal because it needs calendar permissions.
This only handles hourly blocks. I.e. if 30 minutes is filled, we call the entire hour filled.
@dpinney
dpinney / fixingUrlFiles.py
Created October 12, 2019 16:03
Fix all .url Files for MacOS Catalina Version of Safari
#fixingUrlFiles.py
import os
# MacOS Catalina is a little less forgiving about opening .url files that previous OS versions.
# If they're in the wrong format, it fails to open them, just showing a blank browser window.
# Windows will end .url files with a newline and put a space in before the URL= bit.
# This script goes through and changes those bits so Safari will open the files correctly.
# Change "/Users/" to a more specific subfolder to save time.
print('Fixed the following files:')
@dpinney
dpinney / URL for Current Mail Message.scpt
Created June 18, 2017 12:45
Copy a URL to the clipboard that links to the current Mail.app message.
-- Copy a URL to the clipboard that links to the current Mail.app message.
-- Bonus: the URL will work on both iOS and macOS.
-- By David@Pinney.org on 18 June 2017
on run
tell application "Mail"
set s to selection
if (count of s) is not 1 then
display dialog "Please select exactly one message." buttons {"OK"}
return
@dpinney
dpinney / Mail to Calendar Event.scpt
Last active December 8, 2023 23:15
AppleScript to create calendar events reminding you to follow up on Mail.app messages
-- Create a calendar event reminding you to follow up on the currently selected email.
-- Note that this puts everything on a calendar named "Todo" and will fail if that calendar doesn't exist.
-- By David@Pinney.org on 18 June 2017
on run
tell application "Mail"
set s to selection
if (count of s) is not 1 then
display dialog "Please select exactly one message." buttons {"OK"}
return