Jump to content
Fabio

quicking add a new event on Calendar (Mac or Google)

Recommended Posts

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.

Share this post


Link to post

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.

Share this post


Link to post

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

 

Share this post


Link to post
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?

Share this post


Link to post

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

 

Share this post


Link to post
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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...