Modify/change Outlook Calendar event with AppleScript - macos

I have a script that creates an Outlook calendar event from content in an email (also from Outlook). The email contains the name of the event, date/time, and a single attendee's information.
The event is first created with the one attendee that was specified from the email.
I will receive more emails that indicate additional attendees (one per email) and which event the new attendee should be added to.
Right now my script is able to create a calendar event(with location, subject, start/end time, content, and reminder time) and add one required attendee to the event, then send the event to the attendee.
I need to get access to existing events with the same subject and add more attendees to the event.
Right now I'm trying to achieve this with this code:
tell application "Microsoft Outlook"
<...>
set textContent to paragraphs of msgContent
--Check for existing calendar event
set prevEvent to "false"
try
set existingEvent to get (calendar event of calendar whose its subject is item 9 of textContent)
tell existingEvent
make new required attendee at end of attendees with properties {email address:{name:attendeeName, address:attendeeEmail}}
end tell
open existingEvent --This is done so I can make sure it has the info I need. The I'm done it will be changed to "send meeting..."
set prevEvent to "true"
on error
log "Event does not exsist"
end try
if prevEvent = "true" then exit repeat
<...>
--Code to create a new event
set msgToSend to make new calendar event with properties {location:msgLocation, subject:msgSubject, start time:meetingDateTime, end time:endTime, content:msgNewContent, has reminder:true, reminder time:30}
<...>
end tell
I'm not getting an error but my code just exits the try/error so I think my "set existingEvent to" is wrong.

I was able to add an attendee with this code
--Create/add attendee for calendar message invite
make new required attendee at msgToSend with properties {email address:{name:"First Last", address:"first.last#email.com"}}
Where msgToSend is a new calendar event that will be sent out. This event is created by
--Create calendar message invite
set msgToSend to make new calendar event with properties {location:msgLocation, subject:msgSubject, start time:meetingDateTime, end time:endTime, content:msgNewContent, has reminder:true, reminder time:30}
I was not able to determine how to check for and modify existing events using AppleScript. I switched to using Microsoft Flow to achieve my task.

Related

Can't get meeting of outgoing message in Outlook applescript

I want to get meeting of a meeting message from Sent Items folder with AppleScript.
tell application "Microsoft Outlook"
set myFolder to folder "Sent Items" of default account
set meetingList to (every meeting message whose (is read is true)) of myFolder
repeat with theMeeting in meetingList
set meetingType to type of theMeeting
end repeat
end tell
but the I got this error:
error "Microsoft Outlook got an error: Can’t get type of outgoing message id 783." number -1728 from type of outgoing message id 783
it looks like meeting message class inherits form incoming message and not outgoing message. so it's not possible to get meeting message for outgoing emails.
meeting message n [inh. incoming message > message > todoable object > categorizable object > object > …] : A meeting message recieved by the user.
however, I find another solution to use Calendar Suite APIs directly which is a lot better with events processing.

How to use Applescript to delete Conversations whose senders contain email addresses from the Messages app

I want to use applescript to delete conversations from people who sent me messages using email addresses. I want to keep all conversations from mobile numbers, but delete all conversations, in which my correspondent is an email address.
I've tried:
tell application "Messages"
tell every item
delete (every item whose sender contains ".com")
end tell
save
end tell
All scriptable applications have an AppleScript Dictionary that can be accessed from Script Editor via the Window --> Library menu. Reading through an application's dictionary can help you obtain the proper terms for generating a script to do your bidding.
The script below will successfully create a list of chat IDs of all chats (conversations) wherein at least one participant is using an email address. I have not tested the delete section, since I am not interested in deleting anything. I strongly recommend that you run Time Machine or another backup service BEFORE executing that portion of the script, just in case you get unexpected results.
set chatsToKill to {}
tell application "Messages"
set allChats to every chat
repeat with eachChat in allChats
set thePeeps to participants of eachChat
repeat with oneParticipant in thePeeps
if oneParticipant's handle contains "#" then
if chatsToKill does not contain eachChat's id then set end of chatsToKill to eachChat's id
end if
end repeat
end repeat
repeat with deathChat in chatsToKill
delete item 1 of (get every chat whose id = deathChat)
end repeat
end tell

Cancel appointment and associated resources in Outlook when created using EWS Managed API

I am using the EWS Managed API to create appoitments on Exchange 2010.
Appointment appointment = new Appointment(exchangeService);
appointment.Subject = "Sample meeting";
appointment.Body = "Sample meeting body";
appointment.Start = bookingInfo.from;
appointment.End = bookingInfo.from.AddMinutes(bookingInfo.duration);
appointment.Location = meetingRoom.displayName;
appointment.Resources.Add(<my_room_mail>);
// Send the meeting request to all attendees and save a copy in the Sent Items folder.
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
This piece of code create effectively an appoitment in my Outlook but the Meeting Room included as a resource is marked as a "tentative" (not really accepted). So when I want to delete the meeting, the meeting room stay booked (busy/tentative) for the slot and it is impossible to delete the tentative.
If I delete the appoitment from the EWS code (using the appoitment ID), it works as expected, the room is effectively free.
Appointment appointment = Appointment.Bind(exchangeService, new ItemId(itemId));
appointment.Delete(DeleteMode.MoveToDeletedItems);
Do you have any idea of what is the problem ? Outlook right ? Bad appoitment creation or resource booking ?
Ok, I understand that Direct Booking is not compatible with EWS/OWA/Mobile solutions (and also with Outlook 2010/2013 without register tweak).
Direct Booking and Resource Booking Attendant (Auto Accept feature) are conflicting technologies, and if enabled together, unexpected behavior in calendar processing and item consistency can occur.
Check this for more details :
http://msexchangeanswers.blogspot.fr/2009/08/outlook-direct-booking-vs-auto-accept_17.html
http://exchangeserverinfo.net/2013/05/remove-auto-accept-from-outlook-for-all-room-mailbox/
The resource room needs to auto-accept the invitation, so it loses its tentative status. Then when you delete the appointment from your calendar, it should automatically send cancellation to the room. There is a setting on the delete to do this, and I forget off the top of my head if it's the default or not, but I think the initial issue is why the room is not configured to accept or reject the invite sent.

How to cancel an calendar event using ics files?

One of our requirements is to create iCalendar files (.ics) and send them each in emails as an attachment. We are using DDay.Ical.dll to create ics files as under:
// Create a new iCalendar
iCalendar iCal = new iCalendar();
// Create the event, and add it to the iCalendar
Event evt = iCal.Create<Event>();
// Set information about the event
evt.Start = new iCalDateTime(SomeStartTime);
evt.End = new iCalDateTime(SomeEndTime);
evt.Location = "At so and so place";
evt.Description = "Some Description";
evt.Summary = "About Some Subject";
iCal.Method = "PUBLISH";
// Serialize (save) the iCalendar
iCalendarSerializer serializer = new iCalendarSerializer();
serializer.Serialize(iCal, #"iCalendar.ics");
Complete process is:
User1 create an iCal file for specific date and time and send it to User2.
User2 will open the ics file and accept the invitation. An appointment item will be created in User2's LOCAL outlook.
Now, Suppose, because of any reason if appointment is cancelled, then User1 HAS to create an ics file and send it to User2, so that User2 can cancel his event from the local outlook.
How to create such ics file?
File gets created in the same way as the original ics file. The event status will be different. UID will identify the event and sequence number will indicate priority of update, and then the event details will be noted (changes or cancellations)
If you want to change/cancel an event after sending out an invitation, you need to identify the event/appointment by its UID, and allocate a bigger SEQUENCE number than the original ics event.
UID (unique identifier) : https://www.rfc-editor.org/rfc/rfc5545#page-117
Sequence: https://www.rfc-editor.org/rfc/rfc5545#page-138
and set the event status
/ "CANCELLED" ;Indicates event was cancelled.
Status: https://www.rfc-editor.org/rfc/rfc5545#page-92
oh - and method
If you need to send in a cancellation for an event the UID should be same as the original event and the component properties should be set to cancel Ex.
METHOD:CANCEL
STATUS:CANCELLED
Of course this will only 'cancel' the event if the recipient then actually clicks to load/subscribe it into the same calendar app as the first time.
For applications that have 'subscribed' the the remote ics - when they next do an 'update' check the update should be processed and overwrite the original event.
Old thread, but just wanted to give my input.
Also had the problem with outlook showing "not supported format" on a cancel ics. Tried to change METHOD to REQUEST, sort of solved the problem in Outlook, but Gmail and others was not handling it well, looked like an invite, with yes/no/maybe buttons.
After much (MUCH) looking around for solve the problem, I finally realized that the problem was not within the ics file, but how the file was attached to the email. I added it with method:REQUEST. After changing that to method:CANCEL it works well in all clients.
contype = new System.Net.Mime.ContentType("text/calendar");
//contype.Parameters.Add("method", "REQUEST");
contype.Parameters.Add("method", "CANCEL");
contype.Parameters.Add("charSet", "utf-8");
contype.Parameters.Add("name", "invite.ics");
Edit all the events in the ics file using any text file editor (eg. Visual Studio Code) and import modified the calenar again:
I had the issue when i sent mail containing ics file for delete event but in outlook it show me not supported format
then i figured out somewhere on net and i found that i just need to change
METHOD: CANCEL to METHOD: REQUEST
when i import this in outlook

How do I get a _received_ iCal event to run a script?

I'm trying to write an Applescript that will make an outgoing Skype call at times scheduled by received invites from other parties.
I think I'm fine with the script to Skype's API to make the call, however I'm struggling with iCal with either method of
A) getting the script to run in the background and getting the time of all new events, or
B) getting the event alert to run a one-off script.
The issue with option B) is that although you can set events from within iCal so that the alert runs a script, I need to trigger this from events that have been received.
A typical example would be:
All scripts and iCal running on the Host
At 10am a User schedules an event (via google cal on portable device) for 3pm** and invites the the Host.
At 3pm the script on the Host uses Skype API to make a call to the User.
** this could just as equally be on a date in the future and the requirements still hold.
Many thanks for any advice!
Since iCal doesn't have any notifications (some applications do like iChat) you'll have to run a "stay open" applescript application. Something like this will do it for your "B" scenario. NOTE: you will have to add the path to your applescript file (the one that makes your Skype call) in the "applescriptPath" variable.
When launched it will get a listing of all the calendar events you have in iCal. It will then run itself every 5 minutes. When it runs it will check the current events against the list of events it originally made. If there are new events then your applescript will be added as an alarm to the new events. This way it keeps track of the current events between runs and only finds the new ones.
So this script should be a good starting point for you. Remember to save it as a stay-open applescript application. You probably will want to modify it. For example I have it checking every calendar for new events but you may have one particular calendar you want to target. Good luck.
property storedUIDs : {} -- we use this to check for new events, if an event is not in this list then it is new
global applescriptPath
on run
set applescriptPath to (path to desktop as text) & "myAlarm.scpt" -- the path to the applescript which is run as the alarm
end run
on idle
set newEvents to {}
tell application "iCal"
set theCals to calendars
set allUIDs to {}
repeat with aCal in theCals
tell aCal
set theseEvents to events
repeat with anEvent in theseEvents
set thisUID to uid of anEvent
set end of allUIDs to thisUID
if thisUID is not in storedUIDs then
set end of newEvents to contents of anEvent
end if
end repeat
end tell
end repeat
set storedUIDs to allUIDs
if (count of newEvents) is less than 5 then -- this will prevent the first run of the script from adding the alarm to every event
repeat with aNewEvent in newEvents
-- do something with this new events like add an alarm to run an applescript
set theAlarm to make new open file alarm at end of open file alarms of aNewEvent with properties {trigger interval:0, filepath:POSIX path of applescriptPath}
end repeat
end if
end tell
return (5 * 60) -- run every 5 minutes
end idle
on quit
set storedUIDs to {}
continue quit
end quit

Resources