• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scripting calendar - UIDs and moving from one cal to another
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting calendar - UIDs and moving from one cal to another


  • Subject: Re: Scripting calendar - UIDs and moving from one cal to another
  • From: Jay Louvion <email@hidden>
  • Date: Wed, 02 Dec 2015 13:56:05 +0100


The script returns this error, which I am unfortunately a bit at a loss of interpreting:

*** -[BAGenericObjectNoDeleteOSAID moveEventID:toCalID:ofType:]: unrecognized selector sent to object <BAGenericObjectNoDeleteOSAID @0x7fd2b94d9e00: OSAID(1) ComponentInstance(0x8d0003)>

The modified script reads thus:

my moveEventID:"30B44E1A-8468-4193-88AB-CD508AF0CDF0" toCalID:"6674D9DA-44A2-4012-A704-FBFEE1EF2133" ofType:1

on moveEventID:eventID toCal:calName ofType:calType -- Cal type: Local = 0, CalDAV/iCloud = 1, Exchange = 2, Subscription = 3, Birthday = 4
-- create event store and get the OK to access Calendars
set theEKEventStore to current application's EKEventStore's alloc()'s init()
theEKEventStore's requestAccessToEntityType:0 completion:(missing value)


-- check if app has access; this will still occur the first time you OK authorization
set authorizationStatus to current application's EKEventStore's authorizationStatusForEntityType:0 -- work around enum bug
if authorizationStatus is not 3 then
display dialog "Access must be given in System Preferences" & linefeed & "-> Security & Privacy first." buttons {"OK"} default button 1
tell application "System Preferences"
activate
tell pane id "com.apple.preference.security" to reveal anchor "Privacy"
end tell
error number -128
end if


-- get calendars that can store events
set theCalendars to theEKEventStore's calendarsForEntityType:0
-- get the calendar
set theNSPredicate to current application's NSPredicate's predicateWithFormat_("title == %@ AND type == %@", calName, calType)
set theCalendar to item 1 of (theCalendars's filteredArrayUsingPredicate:theNSPredicate)


set TheEvent to (theEKEventStore's calendarItemsWithExternalIdentifier:eventID)'s firstObject()
TheEvent's setCalendar:theCalendar
set {theResult, theError} to theEKEventStore's saveEvent:TheEvent span:((current application's EKSpanThisEvent) + (current application's EKSpanFutureEvents as integer)) commit:true |error|:(reference)
if not theResult as boolean then error (theError's localizedDescription() as text)
end moveEventID:toCal:ofType:

Any ideas? I’m really sorry to be soliciting your help so much, but this form is quite new to me.

TIA,

J.


Jay Louvion | Les Studios Casagrande Sàrl
3, rue Müller-Brun
1208 Geneva
T+4122 840 32 72 
F+4122 840 32 71 
BLOG | Facebook | www.studiocasagrande.com

On 01 Dec 2015, at 23:27, Shane Stanley <email@hidden> wrote:

On 2 Dec 2015, at 7:06 AM, Jay Louvion <email@hidden> wrote:

I’ll try your solution, but I’m at a loss on how to call it - I’m used to subroutines with arguments, but this?

It's a subroutine with arguments, just in a different form.

How do I call it and pass the args?

my moveEventID:"DC685ABB-DD8D-46D0-A4A7-6B8A06913A44" toCalID:"D5B08F90-786A-48B5-A54D-5FE289C797B5"

Do they have to be declared as global? Are they already global once they are declared in the script? Would you be kind enough to give me an example of calling the routine? Thanks in advance.

It's exactly the same as any subroutine, just written differently. See the AppleScript Language Guide, the section on Handlers with Interleaved Parameters. It's just another way of writing:

on moveEventID_toCalID_("DC685ABB-DD8D-46D0-A4A7-6B8A06913A44", "D5B08F90-786A-48B5-A54D-5FE289C797B5")

It's just designed to make it clearer to understand what the arguments are. Type it with the underscores like above and it will compile to the interleaved version anyway.

And regarding the calendarID: it’s only unique on a set machine. I’m working on a series of machines that access the calendars through iCloud, and every calendar (i.e. is local occurence) has it’s own id. I’m using their names, which are the same all-round the synced calendars. Does that modify the routine, name-calling ?

Yes. The catch with names is that you can have more than one calendar with the same name -- one local and one in the cloud, for example. So you need an extra parameter for the type of calendar:

use scripting additions
use framework "Foundation"
use framework "EventKit"

on moveEventID:eventID toCal:calName ofType:calType -- Cal type: Local = 0, CalDAV/iCloud = 1, Exchange = 2, Subscription = 3, Birthday = 4
-- create event store and get the OK to access Calendars
set theEKEventStore to current application's EKEventStore's alloc()'s init()
theEKEventStore's requestAccessToEntityType:0 completion:(missing value)

-- check if app has access; this will still occur the first time you OK authorization
set authorizationStatus to current application's EKEventStore's authorizationStatusForEntityType:0 -- work around enum bug
if authorizationStatus is not 3 then
display dialog "Access must be given in System Preferences" & linefeed & "-> Security & Privacy first." buttons {"OK"} default button 1
tell application "System Preferences"
activate
tell pane id "com.apple.preference.security" to reveal anchor "Privacy"
end tell
error number -128
end if

-- get calendars that can store events
set theCalendars to theEKEventStore's calendarsForEntityType:0
-- get the calendar
set theNSPredicate to current application's NSPredicate's predicateWithFormat_("title == %@ AND type == %@", calName, calType)
set theCalendar to item 1 of (theCalendars's filteredArrayUsingPredicate:theNSPredicate)

set theEvent to (theEKEventStore's calendarItemsWithExternalIdentifier:eventID)'s firstObject()
theEvent's setCalendar:theCalendar
set {theResult, theError} to theEKEventStore's saveEvent:theEvent span:((current application's EKSpanThisEvent) + (current application's EKSpanFutureEvents as integer)) commit:true |error|:(reference)
if not theResult as boolean then error (theError's localizedDescription() as text)
end moveEventID:toCal:ofType:

Cheers,

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Scripting calendar - UIDs and moving from one cal to another
      • From: Shane Stanley <email@hidden>
    • Re: Scripting calendar - UIDs and moving from one cal to another
      • From: Shane Stanley <email@hidden>
References: 
 >Re: Scripting calendar - UIDs and moving from one cal to another (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: silly errors
  • Next by Date: Re: Scripting calendar - UIDs and moving from one cal to another
  • Previous by thread: Re: Scripting calendar - UIDs and moving from one cal to another
  • Next by thread: Re: Scripting calendar - UIDs and moving from one cal to another
  • Index(es):
    • Date
    • Thread