Jump to content
Server Maintenance This Week. ×

iCal select event


This topic is 5717 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I posted in the external data forum about this but A] realized it belongs here, and B] no one has replied due to my waaay to in depth post. (Sorry all.)

I am trying to manipulate an already existing event in iCal from Filemaker via Applescript. I am able to create events no problem. After an event has been added to iCal, I'd like to be able to update or delete the event via Filemaker & Applescript.

I know the UIDs from iCal that I'd like to access but am having trouble getting Applescript to actually select the event.

My code checks to see if the event exists; if it does it should select the event as theEvent to manipulate. If it doesn't exist, it creates a new event as theEvent.

Here's the snippet of my iCal selection code:


tell iCal

    -- find and select or make event

        if exists theUID then

           set theEvent to (select event whose id is theUID)

        else 

           set theEvent to make event at end of events of theCalNum 

        end if



    -- set the event properties

    tell theEvent

      ....blablabla

    end tell

end tell

Thanks in advance!

Link to comment
Share on other sites

I don't have Leopard, but I'm pretty sure you still have to tell it which calendar to look in. This is the syntax I've used in Tiger. I'm including an irrelevant line (to get an UID). But that's just so I can test what syntax is needed to target an event by UID.

property calTitle : "Home"

tell application "iCal"

set theCalendar to calendar named calTitle

tell theCalendar

set theUID to uid of first event

-- don't need above line if you've got an UID, just using for easy testing

set theEvent to item 1 of (every event whose uid is theUID)

end tell

end tell

[And yeah, it's kind of silly to say "item 1 of every event which might match this UNIQUE ID" (kind of over-flexibility, but that's AppleScript for ya. You used to have to do the same thing for the calendar name. Maybe you can be more direct in Leopard, but I have no way to test.]

Edited by Guest
  • Like 1
Link to comment
Share on other sites

Rockin, dude. That gave me the direction I needed. I was trying to access an event without telling which calendar it should be looking in. I was able to combine your "select calendar" code into one line by changing it to "set theEvent to item 1 of (every event of theCalNum whose uid is theUID)" --- bingo! Happy code.


	-- GET or MAKE new calendar # if need be

	set allCalendarTitles to the title of every calendar

	if allCalendarTitles contains theCalendarTitle then

		set theCalNum to (first calendar whose title is theCalendarTitle)

	else

		set theCalNum to (make calendar at end of calendars with properties {title:theCalendarTitle})

	end if







	-- find and select or make event

        if exists theUID then

           set theEvent to item 1 of (every event of theCalNum whose id is theUID)

           --delete (every event of theCalNum whose uid is theUID)

        else 

	    set theEvent to make event at end of events of theCalNum 

        end if

I also tried both "id" and "uid" for iCal references --- Leopard iCal works with both. Rumor has it Tiger and before only likes "uid" -- but I haven't tried it. I'm going to stick with "uid" since all versions of OSX seem to like it.

I may post the rest of my code when it's completed...if anyone is interested that is.

Thanks, Fenton!

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

This topic is 5717 days old. Please don't post here. Open a new topic instead.

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...

Important Information

By using this site, you agree to our Terms of Use.