Hi all!
I handle scheduling and billing for my mental health practice. Our system used to let us set default durations at 50 minutes. They did some “upgrades” and the only default duration is now 60 minutes. I handle hundreds of sessions per week so manually changing the End Time was annoying so I figured I’d write a script to help.
Attached, you’ll see the interface I’m working with. Using a combination of Keyboard Maestro and the included script, I do the following:
• (me) Hover cursor over End Time entry
• (KM) Triple click to select all
• (KM) Cut (storing to clipboard)
• (AppleScript) Do the math/calculations to subtract 10 minutes and store New End Time to clipboard
• (KM) Paste
I finally got my script to work, handling AM vs PM, giving 12AM a value of 0 hours, going from hour 10 to hour 9 but keeping 2 characters in the result, etc… the only time I haven’t figured out yet is when the New End Time crosses the midnight marker. I get negative values.
I know there is a much more slick method of doing this which would be a lot cleaner. If anybody has some insight to rewriting the AppleScript. Thanks in advance!!
-Ryan
--(add to your clipboard as an example of what the existing time would be)
--02:30 PM
set OldEndTime to the clipboard
set OldHour to text 1 thru 2 of OldEndTime --10
set OldColon to text 3 of OldEndTime --:
set OldMin to text 4 thru 5 of OldEndTime --00
set OldSpacer to text 6 of OldEndTime --
set OldPhase to text 7 thru 8 of OldEndTime --AM/PM
set AdjPhase to "" --PM/AM?
set HourPaste to "" --Need a blank starting point?
--Figure out new total of minutes minus 10 based on AM or PM
if OldPhase is "AM" and OldHour is "12" then --12AM gets 0 hour minutes
set SumHours to "00"
set SumMins to OldMin
set TotalMins to SumHours + SumMins
else
if OldPhase is "PM" and OldHour is "12" then --12PM gets 12 hour minutes
set SumHours to (OldHour * 60)
set SumMins to OldMin
set TotalMins to SumHours + SumMins
else
--AM or PM
if OldPhase is "PM" then --PM adds 12 hour minutes
set SumHours to (60 * OldHour)
set SumMins to OldMin
set SumPhase to (12 * 60)
set TotalMins to SumPhase + SumHours + SumMins
else
set SumHours to (60 * OldHour) --AM adds 0 hour minutes
set SumMins to OldMin
set SumPhase to (0)
set TotalMins to SumPhase + SumHours + SumMins
end if
end if
end if
set NewEndTime to TotalMins - 10 --Subtracts 10 minutes, changing OldEndTime from 60 minutes to 50 minutes
log result
if NewEndTime ≥ 720 then --If new time ends up in AM territory, set new phase to AM, otherwise do PM
set NewPhase to "PM"
else
set NewPhase to "AM"
end if
log result
set TrimHour to ((((NewEndTime)) / 60)) as text
log result
if TrimHour = 0 then
set NewHour to "12"
else
if 10 > TrimHour and TrimHour > 1 then
set NewHour to (character 1 of TrimHour as string)
else
set NewHour to (characters 1 thru 2 of TrimHour as string)
end if
end if
log result
if NewHour is "0." and NewPhase is "AM" then
set HourPaste to "12" --Set midnight hour to show "12"... "AM"
--display dialog "1"
else
if NewHour is "12" and NewPhase is "PM" then
set HourPaste to "12" --Set midnight hour to show "12"... "AM"
--display dialog "2"
else
if 22 ≤ NewHour and NewHour ≤ 23 then
set HourPaste to (NewHour - 12) --Set 10PM to 11PM
--display dialog "3"
else
if 13 ≤ NewHour and NewHour ≤ 21 then
set HourPaste to ("0" & (NewHour - 12)) --Set 1PM to 9PM with a leading 0
--display dialog "4"
else
if 10 ≤ NewHour and NewHour ≤ 11 then
set HourPaste to (NewHour) --Set 10AM to 11AM
--display dialog "5"
else
if 1 ≤ NewHour and NewHour ≤ 9 then
set HourPaste to ("0" & NewHour) --Set 1AM to 9AM with a leading 0
--display dialog "6"
end if
end if
end if
end if
end if
end if
--Minutes Calculation
set TrimMin to ((NewEndTime - (NewHour * 60)))
if TrimMin < 10 then
set MinPaste to ("0" & TrimMin)
else
set MinPaste to TrimMin
end if
--(HourPaste & ":" & MinPaste & " " & NewPhase as text)
set the clipboard to (HourPaste & ":" & MinPaste & " " & NewPhase as text)