Jump to content
Server Maintenance This Week. ×

Filemake to iCal


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

Recommended Posts

-- Alarms are not properties, they're elements. You have to make them after the event exists:



set StartDate to date "Saturday, February 24, 2007 9:00:00 AM"

set enddate to date "Saturday, February 24, 2007 10:00:00 AM"

-- entered as "2/24/2007 9:00 AM" Dates will expand to AppleScript's full syntax upon compiling

set alarmTrigger to "-15"



tell application "iCal"

	set newEvent to make new event at end of calendar "Home" with properties {summary:"hello", start date:StartDate, end date:enddate}

	tell newEvent

		make new display alarm at end of display alarms with properties {trigger interval:alarmTrigger}

		-- or sound alarm

	end tell

end tell





set StartDate to date "Saturday, February 24, 2007 8:00:00 AM"

-- allday event

tell application "iCal"

	set newEvent to make new event at end of calendar "Home" with properties {summary:"hello", start date:StartDate, allday event:true}

end tell

Edited by Guest
Link to comment
Share on other sites

Thanks Fenton. I am trying to understand. Where do I put the code? Should I add it on to the Apple Script in the Example File?

Also is it possible to have a option in FMP to add repeated functions like monthly?

Thanks for the help

TMAS

Edited by Guest
Added 2nd Question
Link to comment
Share on other sites

Yes, you would use in the AppleScript in the FileMaker file, which is in a Perform AppleScript step in the script to create an event. I usually write the AppleScript in the Script Editor, compile (by hitting the Enter key), test, then copy/paste into a FileMaker Perform AppleScript step once it works (which is usually not the 1st time B)-). The advantage of Script Editor is that it has syntax coloring, indenting, and error highlighting.

The difference between the two environments is that in Script Editor you must have the: tell "Filemaker Pro" block (or, in your case it would read "FileMaker Developer"). That tell block (along with its: end tell) is not needed within FileMaker Perform AppleScript, because FileMaker already knows who it is. Usually I comment it out. Jonathan Stark did not however, so his will work in either enviroment. So you can ignore this paragraph B)-]

He uses the data from FileMaker fields for the calendar data (duh), and the actual event creation is in this long line:

set theEvent to (make event at end of events of theCalendarNumber with properties {start date:theStartDate, end date:theEndDate, summary:theSummary, description:theDescription})

BTW, if you have a newer version of iCal you do not have to do the "loop thru calendars looking for the name"; you can target a calendar by name directly. See if yours will handle this:

set newEvent to make new event at end of calendar "Home"


You can check if a calendar exists with:




exists calendar "Home"

-- returns true (constant, not text) if true, false if not


you can see what calendars you got with:




name of calendars

-- or, older

title of calendars

When you have a question about AppleScript and an application, look in the Library window of Script Editor. You can read and add the AppleScript dictionaries of apps there. Alternatively you can drag the application file itself onto the Script Editor icon and it will open its AppleScript dictionary (if it exists).

Link to comment
Share on other sites

Thanks for your help, I looked at the dictionary and I get the basic idea. But i have problems adding certain Features?

display alarm & sound alarm

also Repeading (recurrence) chosen from FM

also the choice of color chosen from FM

This is the code I have now. A little changed.

Thanks

(*

Create Event



Copyright © 2005 Jonathan Stark



This script automates the process of creating iCal calendar events from FileMaker records.



You may incorporate this sample code into your program(s) without

restriction.  This sample code has been provided "AS IS" and the

responsibility for its operation is yours.  You are not permitted to

redistribute this sample code as "Jonathan Stark sample code" after having

made changes.  If you're going to redistribute the code, I would appreciate it

if you make it clear that the code was descended from Jonathan Stark's sample

code, but that you've made changes.



Have fun!



Visit www.jonathanstark.com for 

more fun with FileMaker, 

AppleScript, iCal, and more...



*)



-- grab the data from Filemaker

tell application "FileMaker Pro Advanced"

	tell current record

		set theCalendarTitle to cellValue of cell "Person"

		set theSummary to cellValue of cell "Summary"

		set theDescription to cellValue of cell "Description"

		set theStartDate to cellValue of cell "Start Date"

		set theStartTime to cellValue of cell "Start Time"

		set theEndDate to cellValue of cell "End Date"

		set theEndTime to cellValue of cell "End Time"

		set alarmTrigger to cellValue of cell "Alarm Start"

		set alarmTrigger to cellValue of cell "Sound File"

		set recurrence to cellValue of cell "Recurrence"

	end tell

end tell



set theStartDateAsText to theStartDate & " " & theStartTime as text

set theEndDateAsText to theEndDate & " " & theEndTime as text



-- convert text to dates

set theStartDate to date theStartDateAsText

set theEndDate to date theEndDateAsText



-- create the event in iCal

tell application "iCal"

	activate

	

	-- make new calendar if need be

	set allCalendarTitles to the title of every calendar

	if allCalendarTitles contains theCalendarTitle then

		set theCalendarNumber to (first calendar whose title is theCalendarTitle)

	else

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

	end if

	

	

	-- make event

	set theEvent to (make event at end of events of theCalendarNumber with properties {start date:theStartDate, end date:theEndDate, summary:theSummary, description:theDescription, allday event:true})

	

	tell theEvent

		make new display alarm at end of display alarms with properties {trigger interval:alarmTrigger}

		-- or sound alarm

		-- WANT TO ADD: display alarm & sound alarm, also Repeading (recurrence) n different joices from FM, also the choice of color chosen from FM

		

		

	end tell

	

	show theEvent

	

end tell

Link to comment
Share on other sites

The only difference between a display alarm (which I already gave an example of, and a sound alarm, is that a sound alarm also has a sound; which can be the name of a system sound (visible in the Sound Preference Pane, which you choose your alert sound), or it can be a file path to a sound file.

make new sound alarm at end of sound alarms with properties {trigger interval:alarmTrigger, sound name: "blow"}

The color is also pretty simple. iCal's AppleScript dictionary says:

color { RGB color }

which makes it a little difficult to guess the color. But there's utilities to get this from colors.

Example of how to get the current color, and to set the color:

tell application "iCal"

set color of calendar "Home" to {514, 21074, 54484}

-- the default blue color

-- color of calendar "Work"

-- default green returns {11308, 41377, 2827}

end tell

The recurrence is more difficult. iCal's AppleScript dictionary, under event, says:

recurrence (Unicode text) : The iCalendar (RFC 2445) string describing the event recurrence, if defined

Which means that it uses the text like you'd see in the Home.ics file, which looks kind of like a vCard, ie., kind of an ugly mess. Probably the best way to find out exactly what yours would look like is to create it manually in iCal, then open the relevant calendar file (in your home Library/Calendars folder), or export said calendar to your Desktop. Open it with a decent text editor, Find for the event, and see what the lines look like. It's kind of spread over a couple of lines. But the RRule: line has the basics. Example:

RRULE:FREQ=WEEKLY;INTERVAL=1

In AppleScript it looks more like:

set recurrence to "FREQ=WEEKLY;INTERVAL=1;COUNT=10"

-- every week, 10 times

-- or

set recurrence to "FREQ=DAILY;INTERVAL=2;UNTIL=20070531T035959Z"

-- every other day, until 5/31/2007

About the only way to learn how to do this is to try it, then look at the result in iCal and see if it works. It is fairly obvious what you got, or didn't get. You might want to create a new test calendar.

You can also do a search for more code at places like:

http://www.macscripter.net

Apple has an extensive mailing list also. But it's kind of a pain find, or to search through.

Link to comment
Share on other sites

Thanks so much for your help, I'm slowly getting there. One more FM related question. How would create settings in FM? For example I have a pop up menu or radio boxes and it gives me options 1 Month, 12 Month or Always.

These options should represent:

1 Month FREQ=MONTHLY;INTERVAL=1;COUNT=1

1 Year FREQ=MONTHLY;INTERVAL=1;COUNT=12

Always FREQ=MONTHLY;INTERVAL=1;

If I choose 1 Month the field the script looks at is set to FREQ=MONTHLY;INTERVAL=1;COUNT=1

Like a variable field with input from a popup

Sorry for the complicated description.

TMAS

How can that be done

Link to comment
Share on other sites

I think there's 2 choices, either of which have to produce the resultant text you need for the repeating event setting. Which you seem to have figured out. The 2 choices would be whether to build the text in FileMaker, or wait and build it in AppleScript. I'd probably built it in FileMaker, using a calculation field to look at the radio button choice, then produce the text (unstored); produce nothing if there's no radio button choice (non-repeating event).

Put that calculation field on either the current layout, hidden, or create a special AppleScript layout with it. Then flip to the layout before running the AppleScript, or specify the table occurrence and field when specifying the cell in AppleScript; you cannot access a field from AppleScript unless it's: 1. On the current layout, or 2. Specified by table occurrence. I usually just flip to the layout, easier, less breakable.

Then just use that field ("cell" in the AppleScript), same as the other fields.

Remember that if the event is not repeating you don't need to use that weird syntax.

Link to comment
Share on other sites

Alright =)

I run into small issues.

I dont know but it seems the "Allday Event" and color is not working. It seems it is not getting data from FM.

I attached both files, FM and Apple Script.

Would be great if you can coment on them.

Thanks a lot.

TMAS

iCal.zip

Link to comment
Share on other sites

tmas73, you've run into a couple of rather sticky points, which is why we both love and hate AppleScript. I alluded to the first in my post, but only vaguely. Which is that, in AppleScript true and false are constants, NOT text, a different class. So, because a FileMaker field (cell) contains text, you cannot set a property in AppleScript requiring a constant directly to the FileMaker value, even though it looks the same. Within AppleScript, "true" is not the same as the constant true (in Script Editor you'll notice that true without quotes is blue). But you can coerce the text to a constant easily, then it works:

set theAllday to (cellValue of cell "cAllday") as constant

The other problem is even trickier. An AppleScript list, such as {514, 21074, 54484} is a particular class (list, duh). It is not the same as "{514, 21074, 54484}", which is text. So it's rather difficult to pass a value as a list from FileMaker to AppleScript. You can't really pass the brackets, because then they end up inside, rather than outside (a list can contain other lists). It is easy enough to pass the text however, and turn it into a list in AppleScript. I know it sounds like the same thing, but believe me, it isn't, and it can be quite frustrating. Further, an RGB color is a special class of list, composed of the 3 numbers, used only for color. This works; the FileMaker field contains "514, 21074, 54484"

-- tell FileMaker

set colorTxt to cellValue of cell "cColor"

-- end tell

-- convert text numbers to RGB color

set colorList to words of colorTxt -- list

set theColor to colorList as RGB color -- special kind of list, 3 numbers

iCal_fej.zip

Link to comment
Share on other sites

Wow little confused. I understand the idea behind your example but for a beginner im a little lost. I looked at your scene and see that you converted the text to rgb in the script but it does not create a different color just red.

Also if there is True in the Allday event whats the opposite? False or "" creates a Apple script error (Can't make "False" into type constant.).

Thanks

TMAS

Link to comment
Share on other sites

Darn, you're right (as you know). Strangely enough, "true" works, but "false" does not. So I'll revert to plan B, which is actually what I did at first, before I tried the "as constant" fiasco. Basically do an if test, and set the allday event property separately; remove that from the properties you set when you first created the event (the long line).

You do not have to set it to false, as the default for allday event is false. Also, I'm just using the text field, with "Yes" or "No", no need for a calculation with "true" and "false", since it doesn't work anyway.

tell theEvent

if theAllday is "Yes" then

set allday event to true

end if

make new sound alarm at end of sound alarms with properties {trigger date:alarmTrigger, sound name:"blow"}

end tell

The color works well for me. Though they're kind of washed out once they get "aquafied" by the calendar. There's probably some colors work better than others.

Also, I put the AppleScript into FileMaker, in Perform AppleScript script step. It runs faster from there.

iCal_fmforums.zip

Link to comment
Share on other sites

Fenton, i appreciate the work you have done aswell thank you, :clap: i also like your OSX address book file you created if i could find it again.......

Link to comment
Share on other sites

Thanks for all your help I learned a lot on Apple script. One more thing, how can u find the color value? Is there a application for sampling the color , I checked Photoshop and RGB colors there are based on 0-255 so how can I figure out wired numbers like:

43433, 43433, 43433

Thanks

TMAS

Link to comment
Share on other sites

Thanks for all your help I learned a lot on Apple script. One more thing, how can u find the color value? Is there a application for sampling the color , I checked Photoshop and RGB colors there are based on 0-255 so how can I figure out wired numbers like:

43433, 43433, 43433

Thanks

TMAS

go to your applications folder/Utilities.

there is a great little App called Digital color meter.

pick RGB as actual value 16bit. that should give you the result you want. MAC only

Link to comment
Share on other sites

The system color picker is easy to call from AppleScript. It's as simple as: choose color

It returns the 16 bit RGB color, which is what you need. The example chooses the color for a new calendar.

[P.S. What I don't know how to do is convert that 16 bit RGB color to an 8 bit one, so that you could color some text in FileMaker to show the calendar color. Don't really need to however. But a geek somewhere might know :-]

iCal_wColor.fp7.zip

Link to comment
Share on other sites

Something like:

set pickColor to choose color

tell pickColor to set myColor to {(item 1) / 257, (item 2) / 257, (item 3) / 257}



set red to round (item 1 of myColor)

set green to round (item 2 of myColor)

set blue to round (item 3 of myColor)



set FMcolor to red * (256 ^ 2) + green * 256 + blue as integer

set cell "DecimalColor" of current record to FMcolor

Don't call me a geek, though.

Link to comment
Share on other sites

  • 2 weeks later...

I'm wondering here ...it is not exactly what would pass as two way syncing is it? This is only the making an appointment to appear both in iCal as well as in the filemaker system with ...good greef... an event triggers dealings.

The problem as I see it - is that iCal have it's fixed location for it's data, which must be mirrored thru-out the organization, even with the tiny alteration of end time of an event.

It seems like we with earlier versions could use the included web publishing for this?

http://www.filemaker.fm/CDF/fm2ic/fmp2ical.html

However is it not functioning correctly any more, and the developer have seemingly gone tired of his endevour, perhaps due to the appearance of tools like this:

http://spanningsync.com/screencasts/intro/

I can fully see the Applescript capabilities in both grapping and putting data from filemaker into and from iCal, but lack a good example file showing a rock solid two way syncronization ... well some of the methodology is explained here:

http://fmforums.com/forum/showpost.php?post/138841/

But while it's supposed to work in another scenario, is the basics there only it's a huge task compared to the GMail based one menthined above.

--sd

Link to comment
Share on other sites

  • 2 weeks later...

I am using this same script to schedule appointments in ical from filemaker.

however my problem is that i need it to run on filemaker server 8, from a windows filemaker client.

is this possible? I read somewhere that filmaker server doesn't handle applescript the same way the client does, and you need to use a shell script instead so i tried the "send do script event" with the script text. but nothing happens.

if i put the shell script directly into terminal and hit return it works.

does anyone know how to make filmaker server run my shell script?:

Link to comment
Share on other sites

This topic is 6266 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.