Created
November 13, 2019 06:00
-
-
Save codescv/8df37c8a00a4faa545942ed5cb0cbd03 to your computer and use it in GitHub Desktop.
script to add calendar item from 12306 sms
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
on theSplit(theString, theDelimiter) | |
-- save delimiters to restore old settings | |
set oldDelimiters to AppleScript's text item delimiters | |
-- set delimiters to delimiter to be used | |
set AppleScript's text item delimiters to theDelimiter | |
-- create the array | |
set theArray to every text item of theString | |
-- restore the old setting | |
set AppleScript's text item delimiters to oldDelimiters | |
-- return the result | |
return theArray | |
end theSplit | |
on run {input, parameters} | |
set cmd to "echo \"" & input & "\"|perl -pne \"s/.*已购([0-9]+)月([0-9]+)日(.*)次([0-9]+)车(.*)号,(.*)站([0-9]+):([0-9]+)开.*?([0-9A-Z]+).*/\\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9/\"" as string | |
set r to do shell script cmd | |
set split_result to theSplit(r, " ") | |
set m to item 1 of split_result | |
set d to item 2 of split_result | |
set train to item 3 of split_result | |
set cart to item 4 of split_result | |
set seat to item 5 of split_result | |
set station to item 6 of split_result | |
set h to item 7 of split_result | |
set mm to item 8 of split_result | |
set gate to item 9 of split_result | |
set theStartDate to (current date) | |
set month of theStartDate to m as number | |
set day of theStartDate to d as number | |
set hours of theStartDate to h as number | |
set minutes of theStartDate to mm as number | |
set seconds of theStartDate to 0 | |
set theEndDate to theStartDate + (1 * hours) | |
set sss to train & "," & cart & "车" & seat & "号," & station & "检票口" & gate | |
tell application "Calendar" | |
tell calendar "Home" | |
set theEvent to make new event with properties {summary:sss, start date:theStartDate, end date:theEndDate} | |
make new sound alarm at end of sound alarms of theEvent with properties {trigger interval:-120, sound name:"Sosumi"} | |
end tell | |
end tell | |
return sss | |
end run | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment