Last active
February 4, 2023 08:02
-
-
Save jasonsnell/e1821aada020e7b8fc66411c6cfac4e7 to your computer and use it in GitHub Desktop.
Echo Shortcut Notifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# <xbar.title>Echo Shortcut Notifier</xbar.title> | |
# <xbar.version>v1.01</xbar.version> | |
# <xbar.author>Jason Snell</xbar.author> | |
# <xbar.author.github>jasonsnell</xbar.author.github> | |
# <xbar.desc>Display status from Shortcuts.</xbar.desc> | |
import os | |
import datetime | |
theFilePath = '/Users/jsnell/shortcuts-status.txt' | |
modTimesinceEpoc = os.path.getmtime(theFilePath) | |
modificationTime = datetime.datetime.fromtimestamp(modTimesinceEpoc).strftime('%-I:%M %p') | |
with open(theFilePath) as f: | |
for i, line in enumerate(f): | |
print(line.strip()) | |
if i == 0: | |
print('---') | |
print ("Last updated at", modificationTime) |
Don't know version of python you are using, but f-strings read nicer and easier to understand when printing things
print(f"Last updated at {modificationTime}")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FWIW you can simplify this a bit - you don't need to manually count up the lines to get indexes. You can use
enumerate(iterable)
to give you an index, and do this:Oh, and
modificationTime
is already a string, so may as well useprint()
's native concatenation: