Can Apple "Numbers" be automated?

Hi everybody MacScripters.

I would like to collect and manipulate some information which I have stored over the last few months in iCal, in order to display the data in Apple Numbers as charts.

It took me 5 minutes to set up a rough workflow in Automator that can import data from one specific calendar into a text file. That was great and most helpful. I was delighted.

Automator makes scripting actions very simple, no trace however of Apple Numbers in my existing Automator actions.

That would be taking my workflow to the next level and avoid having to manually import my data into a spreadsheet.
I basically want my information from iCal to end in separate cells of Apple Numbers.

Any idea as to where I can find (if they exist) any Apple Numbers actions that can do this?
(or keynote actions for that matter)

Many thanks for the given attention

/Pieter

Numbers is AppleScriptable (somewhat), so I think if Automator can’t do it, you’ll have to insert a script in your workflow.

Hello Adam, thanks for the answer.

Looks like Apple neglected the iWorks suite.
Apple Numbers has become scriptable only in it’s latest incarnation (version 2 that is) and I can find no available Automator actions apart from opening the app and importing data.

I found here a clever example that could pave the road for what I have in mind.

They are “service” scripts but could be useful.

It seems like exporting from iCal into a text file with comma separated values is the way to go.

Any idea as how to do that?

But perhaps better to open another topic on that problem.

Cheers

/Pieter

Here is a little script that I use to plan an appointment for someone from an address book entry, then add it to Ical and finally add the appointment to a numbers document. It will probably be very useful for you, but you’ll need to change a lot of the parimeters.


property emptyString : ""
-------------------------------
try
	set groupOrIndividual to button returned of (display dialog "Is this Contract for a group or an Individual :" buttons {"Group", "Individual"} default button 2)
	if groupOrIndividual is "Individual" then
		tell application "Address Book" to set unsortedList to name of people
		
		set old_delims to text item delimiters
		set text item delimiters to linefeed
		set theList to paragraphs of (do shell script "echo " & quoted form of (unsortedList as string) & "| sort -d -f")
		set text item delimiters to old_delims
		set thePersonChosen to (choose from list theList with prompt " Please choose a Student :")
		if thePersonChosen is false then return
		set thePersonChosen to item 1 of thePersonChosen
	else if groupOrIndividual is "Group" then
		tell application "Address Book" to set unsortedList to name of every group
		set old_delims to text item delimiters
		set text item delimiters to linefeed
		set theList to paragraphs of (do shell script "echo " & quoted form of (unsortedList as string) & "| sort -d -f")
		set text item delimiters to old_delims
		set thePersonChosen to (choose from list theList with prompt " Please choose a Group :")
		if thePersonChosen is false then return
		set thePersonChosen to item 1 of thePersonChosen
	end if
on error
	error "Failed to define if the contract is for a group or an individual"
end try
-------------------------------
try
	tell application "Address Book"
		set thePersonId to 1st person whose name is thePersonChosen
		tell thePersonId
			set thePersonFirstName to my computeValue(first name)
			set thePersonLastName to my computeValue(last name)
			set thePersonFullName to my computeValue(its name)
			if thePersonFullName is emptyString then error
			set {thePersonWorkAddressStreet, thePersonWorkAddressZip, thePersonWorkAddressVille, thePersonWorkAddressPays} to my getAddress(its addresses, "work")
			set {thePersonHomeAddressStreet, thePersonHomeAddressZip, thePersonHomeAddressVille, thePersonHomeAddressPays} to my getAddress(its addresses, "home")
			set thePersonCompany to my computeValue(organization)
			set thePersonJob to my computeValue(job title)
			set thePersondepartment to my computeValue(department)
			set thePersonWorkPhone to my getPhone(phones, "work")
			set thePersonMobile to my getPhone(phones, "Mobile")
			set thePersonHomePhone to my getPhone(phones, "Home")
			set thePersonWorkEmail to my getMail(emails, "work")
			set thePersonHomeEmail to my getMail(emails, "home")
		end tell
	end tell
on error e
	error "Failed to retrieve Student details" & return & e
end try
---------------------
set theStartDate to date (text returned of (display dialog "Please enter the start date and time for the event:" default answer "mardi 2 novembre 2010 22:00:00" buttons "OK" default button 1))
--------------------
set theEventLength to (text returned of (display dialog "Please enter the length in minutes for the event:" default answer "120" buttons "OK" default button 1))
------------
set theEventLocation to button returned of (display dialog "Where is the lesson going to take place :" buttons {"Organisation", "Student's home", "Home"} default button 1)
-----
on computeValue(val)
	if val = missing value then return emptyString
	return val
end computeValue

on getAddress(adr, lab)
	tell application "Address Book"
		repeat with anAddress in adr
			if label of anAddress is lab then
				return {my computeValue(street of anAddress), my computeValue(zip of anAddress), my computeValue(city of anAddress), my computeValue(country of anAddress)}
			end if
		end repeat
	end tell
	return {emptyString, emptyString, emptyString, emptyString}
end getAddress

on getPhone(pho, lab)
	tell application "Address Book"
		repeat with aPhone in pho
			if label of aPhone is lab then
				return my computeValue(value of aPhone)
			end if
		end repeat
	end tell
	return emptyString
end getPhone

on getMail(mail, lab)
	tell application "Address Book"
		repeat with aMail in mail
			if label of aMail is lab then
				return my computeValue(value of aMail)
			end if
		end repeat
	end tell
	return emptyString
end getMail
-----
tell application "iCal"
	set theCalendarNames to title of every calendar --theCalendarNames is a list
end tell
set theCalenderChosen to (choose from list theCalendarNames with prompt " Please choose a calendar :") as string
-----------------------
if theEventLocation is "Organisation" then
	tell application "iCal"
		tell calendar theCalenderChosen
			make new event at end with properties {description:thePersonCompany, summary:thePersonCompany & " " & thePersonLastName & " " & thePersonFirstName & " " & "leçon", location:thePersonWorkAddressStreet & " " & thePersonWorkAddressZip & " " & thePersonWorkAddressVille, start date:theStartDate, allday event:false, end date:theStartDate + theEventLength * minutes}
			set theEvent to first event
			set theEventID to uid of theEvent
		end tell
	end tell
else if theEventLocation is "Student's home" then
	tell application "iCal"
		tell calendar theCalenderChosen
			make new event at end with properties {description:thePersonCompany, summary:thePersonCompany & " " & thePersonLastName & " " & thePersonFirstName & " " & "leçon", location:thePersonHomeAddressStreet & " " & thePersonHomeAddressZip & " " & thePersonHomeAddressVille, start date:theStartDate, allday event:false, end date:theStartDate + theEventLength * minutes}
			set theEvent to first event
			set theEventID to uid of theEvent
		end tell
	end tell
else if theEventLocation is "Home" then
	tell application "iCal"
		tell calendar theCalenderChosen
			make new event at end with properties {description:thePersonCompany, summary:thePersonCompany & " " & thePersonLastName & " " & thePersonFirstName & " " & "leçon", location:"41 rue Marius Berliet,69008,Lyon", start date:theStartDate, allday event:false, end date:theStartDate + theEventLength * minutes}
			set theEvent to first event
			set theEventID to uid of theEvent
		end tell
	end tell
end if

tell application "Numbers"
	activate
	open ":Users:alan:Documents:speakUP:Suivi des heures:Suivi des Heures :Date des Leçons.numbers"
	tell sheet 1 of document 1
		tell table 1
			tell last row
				add row below
				set value of cell 1 to thePersonCompany
				set value of cell 2 to thePersonLastName
				set value of cell 3 to thePersonFirstName
				set value of cell 4 to theEventLocation
				set value of cell 5 to theStartDate as string
				set value of cell 6 to theStartDate as string
				set value of cell 7 to theStartDate + theEventLength * minutes as string
				set value of cell 8 to theEventLength / 60 as string
				set value of cell 9 to theStartDate as string
				set value of cell 10 to theEventID
				set value of cell 11 to (current date) as string
			end tell
		end tell
	end tell
end tell

tell application "Numbers"
	activate
	open ":Users:alan:Documents:speakUP:Suivi Clients" & ":" & thePersonCompany & ":" & thePersonLastName & thePersonFirstName & "FeuilleSignatures.numbers"
	tell sheet 1 of document 1
		tell table 1
			tell last row
				add row below
				set value of cell 2 to theStartDate as string
				set value of cell 3 to theEventLength / 60
			end tell
		end tell
	end tell
end tell

Good luck