Jump to content

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


Fabio

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.

Link to comment

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

 

Link to comment

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

 

Link to comment
  • 6 months later...
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
  • 1 year later...
  • 1 month later...
  • 1 year later...
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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...