Last active
October 27, 2022 15:33
-
-
Save jasonsnell/9b95468474d6cc864d4feb6e2a5ca9cf to your computer and use it in GitHub Desktop.
Podcast Noter AppleScript
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
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 |
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
I can't seem to get this to work. I've changed line 14 to my desktop and I have a file with today's date (YYYYMMDD format) in the name located there.
Script Editor Replies:
If I run it from Terminal, I get this:
Any advice? :)