I'll paste my actual code below.
It's a script that creates an Outlook Calendar item. It works like:
1. Copy selected text
2. Regex match possible location, time, date, then subject.
2b. Pop up a Msg of the haystack and matches.
3. Open the Calendar form
4. Use Outlook's hotkeys to enter the things.
If I use if on this text:
Time correction: 12:00 NOON Matt Smith. 1st floor conf.
Then I get this:
---------------------------
Clipboard is
===================
[Time coection: 12:00 NOON Matt Smith. floor conf.]
===================
date is [ 1st]
time is [12:00 ]
location is [rr]
Subject is [Time]
---------------------------
Notice that the "rr" in correction is matched as a location, but it is also removed from the haystack text. "1st" is also removed, but "12:00" is not. I'd like to know why it does this, so I can do it on purpose.
Here is the entire script (sorry about lack of syntax highlighting)
Code: Select all
#NoEnv
#SingleInstance force
;#################################
;Menu, Tray, Icon, %A_ScriptDir%\magnet-arrow-fugueIcon16.ico
AutoTrim Off ; Retain any leading and trailing whitespace on the clipboard.
ClipboardOld = %ClipboardAll%
Clipboard = ; Must start off blank for detection to work.
Send ^c
ClipWait, 1
if ErrorLevel ; ClipWait timed out.
{
MsgBox, No text selected(?)`n`n (Script exiting.)
ExitApp
}
;######## GET LOCATION #####################
reLocation := "\b[a-z]{2,}'s\s(office|room|classroom|rm)|((Resource\s)(Room|Rm\s)|RR)|(room|rm)\s(A|B|C|D|\d{3})|(Counseling)|(Office)\b"
reLocPre := "in\s(the\s)?" ; don't capture
RegExMatch(Clipboard, "i)" reLocPre "(\K)" reLocation, myLocation)
if (!myLocation)
{
RegExMatch(Clipboard, reLocation, myLocation)
}
;######## GET TIME #########################
reTime := "\b(([0-2]?[0-9]:[0-5])[0-9](\s?(pm|am|p|a)?)|[12]?[0-9](pm|am|p|a))|(before\s|after\s)school|noon|in the morning\b"
RegExMatch(Clipboard, "i)" reTime, myTime)
If (myTime = "before school" )||(myTime = "in the morning")
{
myTime := "7:30 am"
}
Else If (myTime = "after school")
{
myTime := "2:45 pm"
}
;######### GET DATE ########################
re2WeeksPre := "(((2|two)\sweeks\s)(from\s)?|((week\s)?after next\s(on\s)?))" ; don't capture
re2WeeksSuf := "(((in\s)?(2|two) weeks)|((week )?after next))" ; don't capture
re1WeekPre := "(next\s(week\s)?)|(week\s(from|after)\s)" ; don't capture
re1WeekSuf := "(next( week)?)" ; don't capture
reNumDate := "\b(([0-9]|10|11|12)[-./]([0-2]?[0-9])[-./](20)?[0-9][0-9])"
reWDay := "\b(((Mon|Tue(s)?|Wed(nes|s)?|Thu(rs|r)?|Fri|Sat(ur)?|Sun))(day|d)?|(day\safter\s)?tomorrow)\b"
reMonth := "\b((Jan|Feb)(ru(ary)?)?|Mar(ch)?|Apr(il)?|May|Jun(e)?|Jul(y)?|Aug(ust)?|(Sep(tem)?|Oct(o)?|Nov|Dec)(em)?(ber)?)\b"
re1st31st := "\b(?<!:)([0-2]?[0-9]|30|31)(st|nd|rd|th)?(?!:)\b"
RegExMatch(Clipboard, reNumDate, myDate) ; e.g. 01-01-2016
if (!myDate)
{
RegExMatch(Clipboard, "i)" reMonth "(\s)" re1st31st "|" re1st31st "(\sof\s)" reMonth, myDate) ; e.g. Jan 1st | 1st of Jan
if (!myDate)
{
RegExMatch(Clipboard, "i)" re2WeeksPre "\K" reWDay "|" reWDay "(?=\s" re2WeeksSuf ")", myDate) ; e.g. Mon in two weeks
myDatePrefix := "2 weeks "
if (!myDate)
{
RegExMatch(Clipboard, "i)(" re1WeekPre ")\K" reWDay "|" reWDay "(?=\s" re1WeekSuf ")", myDate) ; e.g. next Mon
myDatePrefix := "next "
if (!myDate)
{
RegExMatch(Clipboard, "i)" reWDay, myDate) ; e.g. Monday
myDatePrefix =
if (!myDate)
; MsgBox ReWday = %reWDay% myDate = %myDate%
{
RegExMatch(Clipboard, "i)" reMonth, myDateM) ; e.g. (January)(1st)
RegExMatch(Clipboard, re1st31st, myDateD)
myDate = %myDateM% %myDateD%
}
}
}
}
}
;sleep, 500
myDate = %myDatePrefix%%myDate%
;#########GET SUBJECT#########################
StringReplace, clipboard, clipboard, %myLocation%, , All ; removes myLocation so that it's not mistaken as the Subject.
StringReplace, clipboard, clipboard, %myDate%, , All ; removes myDate
reSubject := "\b[A-Z][a-z]*(\s[A-Z][a-z]*)?\b"
reSubjPre := "meeting\sfor" ; don't capture
reSubjSuf := "'s" ; don't capture
RegExMatch(Clipboard, "i)" reSubjPre "(\K\s)" reSubject, mySubject)
if (!mySubject)
{
RegExMatch(Clipboard, reSubject "(?=\s" reSubjSuf ")", mySubject)
if (!mySubject)
{
RegExMatch(Clipboard, reSubject, mySubject)
}
}
;#############################################
MsgBox Clipboard is`n===================`n [%Clipboard%]`n===================`n`ndate is [%myDate%]`ntime is [%myTime%]`nlocation is [%myLocation%]`n Subject is [%mySubject%]
;MsgBox date is [%myDate%]`ntime is [%myTime%]`nlocation is [%myLocation%]`n Subject is [%mySubject%]
run, C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE /c ipm.appointment
WinWaitActive, Untitled - Appointment, , 15
SendInput, !u%mySubject% ; Subject
SendInput, !t%myDate%
SendInput, !t{Tab}{Tab}%myTime%
SendInput, !i%myLocation%
Clipboard = %ClipboardOld% ; Restore previous contents of clipboard.
ExitApp
Esc::
;SoundPlay *-1
Clipboard = %ClipboardOld% ; Restore previous contents of clipboard.
ExitApp
/*
TEST STRINGS
There is a meeting for Jimmy Bob after school next Wed in the Resource Room.
Let's do Monday in 2 weeks in Rm 101.
The transition meeting for Jenny is at noon in the A Commons.
Nov 17 before school for Billy's thing.
Day after tomorrow in the morning.
Navigation of Outlook Calendar Item Form: (updated 10-10-2018)
/c ipm.appointment
Subject !u
Location !i
Start date !t
Start time !t{Tab}{Tab}
End Date !d
End time !d{Tab}{Tab}
Notes !d{Tab}{Tab}{Tab}{Tab} Developer Tab must be hidden.
Save and Close !s
*/
EDIT: Screenshot