How do I export Dates from Numbers 3 to iCal?

Hi,


I need to repoen this discussion, 4 years later :

https://discussions.apple.com/thread/2377933?answerId=11273570022#11273570022


But now, it's for Number 3, since it support AppleScript.


I've tried the script from Yvan, but I've got error.


error "Il est impossible d’obtenir item 8 of {\"Il est impossible de rendre «class NmCR» \", \"A1:C3\", \" of «class NmTb» 1 of «class NmSh» 2 of document \", \"Sans titre 2\", \" of application \", \"Numbers\", \" en type text.\"}." number -1728 from item 8 of {"Il est impossible de rendre «class NmCR» ", "A1:C3", " of «class NmTb» 1 of «class NmSh» 2 of document ", "Sans titre 2", " of application ", "Numbers", " en type text."}


Any help ?


🙂

Posted on May 13, 2014 1:48 PM

Reply
15 replies

May 14, 2014 1:09 AM in response to SGIII

Here is a sample of the table :

http://www.lesyeuxouverts.com/Sample-Numbers-3-to-Calendar.zip


The script has to look for each row :

- read the Theater colum to determin wich calendar to work with

- add Name + " - " + File to set event name

- get Start and End colums to set star and end all day event


I'm trying to make a script to sent events from Numbers 3 table above to Calendar following those rules :

- if events doesn't exist in Calendar, but exist in Numbers, it create it in Calendar

- if events already exist in Calendar, and are exactly the same, it does nothing

- if events already exist in Calendar, and are different, it updates from Numbers to Calendar

- if events exist in Calendar but no in Number, it deletes event in Calendar


🙂

May 14, 2014 1:33 AM in response to Vincdeladrome

Good news ! Yvan has helped me by email, and here is the script from the original post working with Numbers 3.2 :


--{code}

--[SCRIPT create_ical_events_from_Numbers'14]

(*

Enregistrer le script en tant que Script : create_ical_events_from_Numbers'09.scpt

déplacer le fichier ainsi créé dans le dossier

<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:

Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.


Sélectionner les cellules d'une table de Numbers qui décrivent des 'events'

La table est censée contenir:

une colonne avec le résumé des événements

une colonne avec les date_heures de début

une colonne avec les date_heures de fin

Éditer la property 'leCalendrier' en fonction du nom du calendrier à alimenter.


Aller au menu Scripts , choisir Numbers puis choisir create_ical_events_from_Numbers'14


Le script crée les évènements dans iCal




--=====


L’aide du Finder explique:

L’Utilitaire AppleScript permet d’activer le Menu des scripts :

Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.

Cochez la case “Afficher le menu des scripts dans la barre de menus”.

Sous 10.6.x,

aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript

puis cocher la case “Afficher le menu des scripts dans la barre des menus”.


--=====


Save the script as a Script: create_ical_events_from_Numbers'14.scpt


Move the newly created file into the folder:

<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:

Maybe you would have to create the folder Numbers and even the folder Applications by yourself.


In a table from Numbers '14,

select cells describing 'events'.

This table is supposed to embed :

a column storing events summaries

a column storing start datetime

a column storing end datetime.


Edit the instruction defining the calendar name to fit your needs.


Go to menu Scripts, choose Numbers, then choose create_ical_events_from_Numbers'09


The script will create new events in iCal.


--=====


The Finder’s Help explains:

To make the Script menu appear:

Open the AppleScript utility located in Applications/AppleScript.

Select the “Show Script Menu in menu bar” checkbox.

Under 10.6.x,

go to the General panel of AppleScript Editor’s Preferences dialog box

and check the “Show Script menu in menu bar” option.


--=====


example:

event #1 18 avr. 2010 05:35 19 avr. 2010 15:35

event #2 19 avr. 2010 05:35 20 avr. 2010 15:35

event #3 20 avr. 2010 05:35 21 avr. 2010 15:35

event #4 21 avr. 2010 05:35 22 avr. 2010 15:35


--=====


Yvan KOENIG (VALLAURIS, France)

2010/03/25

2011/09/30 cosmetic changes.

2012/09/03 edited for Mountain Lion.

2014/04/14 edited for Numbers '14

*)

--=====


property leCalendrier : "TEST"

property |nbrPropriétésParÉvènement| : 3


--=====


on run

local leDocument, laFeuille, laTable, numLigne1, numColonne1, numLigne2, numColonne2, |lesPropriétés|, c

set {leDocument, laFeuille, laTable, numLigne1, numColonne1, numLigne2, numColonne2} to my get_SelParams()

set numColonne2 to numColonne1 + |nbrPropriétésParÉvènement| - 1

tell application "Numbers" to tell document leDocument to tell sheet laFeuille to tell table laTable

repeat with r from numLigne1 to numLigne2

set |lesPropriétés| to {}

repeat with c from numColonne1 to numColonne2

copy (value of cell r of column c) to end of |lesPropriétés|

end repeat -- with column

(*

Now, |lesPropriétés| contains

- the event description

- the start date_time

- the end date_time

*)

my makeEvent(|lesPropriétés|)

end repeat

end tell -- Numbers

end run


--=====


on makeEvent({|résumé|, |début|, fin})

tell application "Calendar"

set nbc to count (every calendar whose name = leCalendrier)

try

repeat with n from 1 to nbc

make new event at the end of events of (calendar n whose name is leCalendrier) with properties {summary:|résumé|, start date:|début|, end date:fin} #, allday event:false}

end repeat

end try

end tell


(*

tell application "Calendar"

try

make new event at the end of events of (first calendar whose name is leCalendrier) with properties {summary:|résumé| , start date:|début| , end date:fin} # , allday event:false}

end try

end tell

*)

end makeEvent


--=====

(*

set { leDocument, laFeuille, laTable, numLigne1, numColonne1, numLigne2, numColonne2} to my get_SelParams()

tell application "Numbers" to tell document leDocument to tell sheet laFeuille to tell table laTable


Edited to match Numbers '14 features.

*)

on get_SelParams()

local le_Document, la_Feuille, i, la_Table, haut_gauche, bas_droite

local num_Ligne1, num_Colonne1, num_Ligne2, num_Colonne2

tell application "Numbers" to tell document 1

set le_Document to its name

set la_Feuille to name of active sheet


tell sheetla_Feuille

set selectionAvailable to false

repeat with i from 1 to count table

if selection range of table i is not missing value then

set selectionAvailable to true

exit repeat

end if

end repeat

if not selectionAvailable then

if my parleAnglais() then

error "No sheet has a selected table embedding at least one selected cell !"

else

error "Aucune feuille ne contient une table ayant au moins une cellule sélectionnée !"

end if

end if

set la_Table to name of table i

tell table la_Table

tell selection range

set {haut_gauche, bas_droite} to {name of first cell, name of last cell}

end tell


tell cell haut_gauche to set {num_Ligne1, num_Colonne1} to {address of its row, address of its column}

if haut_gauche is bas_droite then

set {num_Ligne2, num_Colonne2} to {num_Ligne1, num_Colonne1}

else

tell cell bas_droite to set {num_Ligne2, num_Colonne2} to {address of its row, address of its column}

end if

end tell -- table…

end tell -- sheet…

return {le_Document, la_Feuille, la_Table, num_Ligne1, num_Colonne1, num_Ligne2, num_Colonne2}

end tell -- Numbers

end get_SelParams


--=====


on decoupe(t, d)

local oTIDs, l

set oTIDs to AppleScript'stext item delimiters

set AppleScript'stext item delimiters to d

set l to text items of t

set AppleScript'stext item delimiters to oTIDs

return l

end decoupe


--=====


on parleAnglais()

local z

try

set z to localized string "Cancel" from table "Numbers" in bundle path to application "Numbers"

on error

set z to "Cancel"

end try

return (z is not "Annuler")

end parleAnglais


--=====

--[/SCRIPT]

--{code}



Now, I'm looking to adapt it as explain in my precedent post...

May 14, 2014 9:04 AM in response to Vincdeladrome

Glad you were able to solve your question. Yvan's script contains a useful handler that captures the parameters of the selected range (the first and last row, and first and last column of the selected cells and which table, sheet, and document they are in). For those challenged in French or just preferring shorter scripts, in Numbers 3 it can be simplified to something like this:


SG




on get_SelParams()

try

tell application "Numbers"

set docName to front document's name

set sheetName to documentdocName'sactive sheet'sname

set tableName to document docName's sheet sheetName's first table's name whose selection range's class is range

tell documentdocName'ssheetsheetName'stabletableName'sselection range

tell first cell to set {firstRowNum, firstColNum} to {its row's address, its column's address}

tell last cell to set {lastRowNum, lastColNum} to {its row's address, its column's address}

end tell

return {docName, sheetName, tableName, firstRowNum, firstColNum, lastRowNum, lastColNum}

end tell

on error

display dialog "Problem getting values. Did you select cells?" buttons "Cancel"

end try

end get_SelParams

May 14, 2014 2:16 PM in response to SGIII

Or even simpler:



on get_SelParams()

try

tell application "Numbers"

set t to front document's active sheet's first table whose selection range's class is range

tell t'sselection range

tell first cell to set {firstRowNum, firstColNum} to {its row's address, its column's address}

tell last cell to set {lastRowNum, lastColNum} to {its row's address, its column's address}

end tell

return {front document'sname, t'sparent'sname, t'sname, firstRowNum, firstColNum, lastRowNum, lastColNum}

end tell

on error

display dialog "Problem getting values. Did you select cells?" buttons "Cancel"

end try

end get_SelParams



SG

Jan 21, 2015 12:51 PM in response to yelladogs

That's a good question. I remember wondering that myself when first starting out with AppleScript. Unlike, say, Excel, Numbers does not have built-in macros or scripting that is stored in a workbook.


In Yosemite, here is what you do.


First, check in System Preferences > Security & Privacy > Privacy (tab at top) > Accessibility (choice on left) to make sure Script Editor is checked under 'Allow the apps below to control your computer'. (You may have to 'unlock' the lock lower left to check it if it is not already checked.)


Then all you need to do is this:


  1. Open the application named Script Editor, located in the Applications > Utilities folder. (Pre-Yosemite the name was AppleScript Editor).
  2. Select the script from the post above, command-c to copy, and in Script Editor File > New command-v to paste into the top box.
  3. To run the script, click the triangle 'Run' button at the top.


That's it. Easier than getting a lot of Numbers formulas to work. There are ways to put frequently used scripts in the menu and even trigger them with keyboard shortcuts, but you may not need that here.



SG

Jan 21, 2015 1:05 PM in response to t quinn

Thanks T Quinn.


I feel like I am stepping off the high dive without knowing how to swim! My script editor doesn't look like yours. When I searched for it in spot light this is what came up. I'm assuming it is correct? I'm on Yosemite 10.10. 1 and Numbers is 3.5.2


I really need to be able to insert dates into Numbers and have those dates show up in iCal so I don't have to set it up twice. I am assuming this will work if I can get it done crrectly?

Thanks


User uploaded file

Jan 21, 2015 1:34 PM in response to yelladogs

You can save it as a script. It will always be "outside" Numbers, though if you use it often, there are ways to have it appear as a menu pick in Numbers > Services (and, if you want, be attached to a keyboard shortcut) or have it appear in a scripts menu associated with Numbers. But first things first: see if you can get it to do what you want when you run it from Script Editor. Without knowing the specifics of the structure of your Numbers document, it's hard to tell whether you may have some work to do in order to adapt the scripts to your needs.


SG

Jan 21, 2015 2:12 PM in response to yelladogs

Not dumb at all. This can be confusing and is very different from, for example, how VBA works with Excel. What you need to do (at lest until you've finalized the script and perhaps want it to appear in the Numbers > Services menu or a script menu) is simply have Numbers and Script Editor open at the same time. Then when you're ready to run the script choose Script Editor and click the 'run' triangle. The script has to correctly target your Numbers document.


SG

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do I export Dates from Numbers 3 to iCal?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.