Skip to content

Instantly share code, notes, and snippets.

@jasonsnell
Last active October 27, 2022 15:33
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonsnell/9b95468474d6cc864d4feb6e2a5ca9cf to your computer and use it in GitHub Desktop.
Save jasonsnell/9b95468474d6cc864d4feb6e2a5ca9cf to your computer and use it in GitHub Desktop.
Podcast Noter AppleScript
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
# Sample Keyboard Maestro macros at
# <https://sixcolors.com/wp-content/uploads/2022/01/Podcast-Noter-Macros.kmmacros.zip>
on run argv
try
set theNote to (item 1 of argv)
on error
set theNote to ""
end try
set theSavePath to "/Users/jsnell/Desktop/" -- put your own path here
set theDatematch to (do shell script "date '+%Y%m%d'")
set theLatestMatch to date "Monday, January 1, 2001 at 12:00:00 AM"
try
tell application "Finder"
set theMatches to (every file of (POSIX file theSavePath as alias) whose name contains theDatematch)
set theWinner to item 1 of theMatches
repeat with i from 1 to (count of items in theMatches)
set theMatched to creation date of item i of theMatches
if theMatched > theLatestMatch then
set theLatestMatch to theMatched
set theWinner to item i of theMatches
end if
end repeat
set theStartTime to (creation date of theWinner)
end tell
on error
display notification "No session found."
return
end try
set theOffset to ((current date) - theStartTime)
set theTimeStamp to secondstoHMS from theOffset
if (theNote as text) = "" then
set theStamper to theTimeStamp
else
set theStamper to (theTimeStamp & " - " & (theNote as text))
end if
set theSafeDatematch to (do shell script "date -j -f '%A, %B %e, %Y at %I:%M:%S %p' '" & theStartTime & "' '+%b %d %H%M'")
do shell script ("echo " & quoted form of theStamper & " >> " & quoted form of (theSavePath & "Notes - " & theSafeDatematch & ".txt"))
end run
on secondstoHMS from theSeconds
tell theSeconds to return my pad(it div hours) & ":" & my pad(it mod hours div minutes) & ":" & my pad(it mod minutes)
end secondstoHMS
on pad(v)
return text -2 thru -1 of (v + 100 as text)
end pad
@RandyWalker
Copy link

24-hour time strikes again! Your script is for 12-hour clocks, not 24. Once I switched my system to 12-hour time, it works just fine from Terminal and Stream Deck. (Still gives the same error in Script Editor thought!)

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