Fabio Posted February 13, 2019 Share Posted February 13, 2019 Hi, Folks! What is the best way (or possible) to add quick events to Mac calendar (or maybe to Google one) by using Alfred? I meant, using natural language... (e.g., meet with John tomorrow at 5 pm) I've found some old workflows, but they seem not to be working properly. Thanks a lot, Fabio. Tony D 1 Link to comment
deanishe Posted February 15, 2019 Share Posted February 15, 2019 Neither Calendar.app nor Google Calendar exposes an API for adding events using natural language. The best you can do is use AppleScript to activate Calendar.app and simulate ⌘N to open the Quick Entry box, and then create your event using that. Link to comment
Fabio Posted February 16, 2019 Author Share Posted February 16, 2019 Many thanks, Deanish!!!! Here is the code I wrote... if you have any improvement, please let us know!! on run set the clipboard to "{query}" as text tell application "Calendar" to activate delay 0.5 tell application "System Events" keystroke "n" using {command down} keystroke "v" using {command down} keystroke return delay 0.5 keystroke return key code 48 using {command down} end tell return "{query}" end run bivalvegruff 1 Link to comment
bivalvegruff Posted February 17, 2019 Share Posted February 17, 2019 On 2/16/2019 at 3:58 PM, Fabio said: Many thanks, Deanish!!!! Here is the code I wrote... if you have any improvement, please let us know!! Trying to make a workflow with this, with a keyword followed by a script – which coding language is this / should I select? Link to comment
deanishe Posted February 17, 2019 Share Posted February 17, 2019 It's AppleScript. Paste it in a Run Script box with Language = /usr/bin/osascript (AS). bivalvegruff 1 Link to comment
bivalvegruff Posted February 19, 2019 Share Posted February 19, 2019 Great! I added a similar script in the same workflow, but with the ⌘ modifier, for when you want to edit the details before saving. It opens the list of calendars for you (I often add things to both my personal and my work calendar.) on run set the clipboard to "{query}" as text tell application "Calendar" to activate delay 0.5 tell application "System Events" keystroke "n" using {command down} keystroke "v" using {command down} keystroke return delay 0.5 key code 48 key code 125 end tell return "{query}" end run Narath 1 Link to comment
Marko Posted September 18, 2019 Share Posted September 18, 2019 @bivalvegruff , I 've tried your script and it works only if Calendar Window is open. I am curious if you have changed your script since February or use different solution? Thanks! :) Link to comment
deanishe Posted September 18, 2019 Share Posted September 18, 2019 On 2/15/2019 at 1:41 PM, deanishe said: Neither Calendar.app nor Google Calendar exposes an API for adding events using natural language. This is actually not true: Google Calendar does have such an API. It's rather complex to use, however, as you have to mess about with OAuth2 authentication. 2 hours ago, Marko said: I 've tried your script and it works only if Calendar Window is open. The problem is almost certainly because delay 0.5 isn't long enough for Calendar.app to launch and come to the front on your machine if it isn't already running. As a result, the simulated keypresses aren't being registered by Calendar.app. Increase the delay (e.g. delay 1.5) until it's long enough for the script to work on your machine. Link to comment
BocciaMan Posted August 21, 2021 Share Posted August 21, 2021 I've tried this script after adding a hotkey trigger. All it does is open calendar and adds query to a new event that you must modify. Am I doing something wrong? Link to comment
Kim Aldis Posted October 18, 2021 Share Posted October 18, 2021 Fantastical uses Apple calendars and is scriptable. There's also a Fantastical workflow for Alfred. Link to comment
GeorgeChungus Posted March 17, 2023 Share Posted March 17, 2023 On 2/19/2019 at 12:03 PM, bivalvegruff said: on run set the clipboard to "{query}" as text tell application "Calendar" to activate delay 0.5 tell application "System Events" keystroke "n" using {command down} keystroke "v" using {command down} keystroke return delay 0.5 key code 48 key code 125 end tell return "{query}" end run Works perfectly. Calendar doesn't need to be running (it opens it), the query accepts natural language "test test event friday 7a", it automatically syncs to my google calendar, and google calendar emails me about it x hours beforehand. Perfect. Link to comment
n30nra1n Posted March 20, 2023 Share Posted March 20, 2023 On 8/22/2021 at 2:58 AM, BocciaMan said: I've tried this script after adding a hotkey trigger. All it does is open calendar and adds query to a new event that you must modify. Am I doing something wrong? I am new to this, and I get the same thing; any advice would be much welcomed. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now