OK, así que respondo a mi propia pregunta. Es posible hacer lo que quería, aunque no encontré una solución satisfactoria.
La respuesta corta es: no pude encontrar ninguna manera de utilizar applescript con la manipulación directa de la interfaz gráfica (por ejemplo, los clics). Encontré una manera usando alternativas de teclas. Para hacer el trabajo exacto que necesitaba, la siguiente secuencia servirá:
-- después de abrir el documento en Numbers, abre la ventana de compartir:
tell application "System Events"
tell process "Numbers"
delay 1
tell menu bar 1
tell menu bar item "Share"
tell menu "Share"
delay 1
click menu item "Share Link via iCloud…"
end tell
end tell
end tell
end tell
-- una vez abierta la ventana desplegable de acciones, utilice la siguiente combinación de teclas
tell application "System Events"
--add tabs
delay 1
key code 48
delay 1
key code 48
delay 1
-- use arrows to move to the right part of the 'Share' window
key code 124
delay 1
key code 124
delay 3
-- click return
key code 36
delay 8
-- save the file and close it
keystroke "s" using {command down}
delay 4
keystroke "w" using {command down}
La respuesta larga es: es un dolor de cabeza por una serie de razones.
En primer lugar, cuando se crea un archivo Numbers, es un archivo simple. Sin embargo, cuando se comparte, o cuando se guarda en iCloud, se convierte en un paquete. Applescript ve los paquetes como carpetas, por lo que hay que comprobar antes de hacer nada si lo que se está tratando es una carpeta o un paquete. Luego puedes pasar a las operaciones de compartición.
Ahora bien, no he encontrado ninguna forma principal de interceptar cuándo exactamente un archivo se convierte en un paquete. Es decir, cuando abres un archivo de Numbers y pides que se comparta, verás que Numbers te da un mensaje de "preparando el documento para compartir". Esto, según descubrí, es cuando el archivo se transforma en un paquete. Hay una propiedad que se puede utilizar para comprobar si una ruta dada corresponde a un paquete o a un solo archivo: se podría hacer un bucle mientras (la carpeta paquete del item_info es falsa) y luego continuar, pero esta propiedad se pone como verdadera mucho antes de que Numbers haya terminado su propio trabajo de "preparación del documento para compartir". Así que sólo pude adivinar cuándo puedo continuar e ir a la parte de compartir del script. Puse un retraso aproximado de 30 segundos cuando un archivo aún no es un paquete, lo que debería dar tiempo de sobra para que Numbers termine sus transformaciones del archivo a compartir:
if (this_package_folder is false) and (this_extension is in the extension_list) then
delay 30
end if
En segundo lugar, usted debe estar en una buena red, para que todas las operaciones relacionadas con Numbers en iCloud puedan realizarse sin problemas -- de lo contrario, iCloud te dará mensajes de error que bloquearán la ejecución del script.
En tercer lugar, tienes que ocuparte de los archivos .DS_Store y de otros archivos que puedan estar dentro de la carpeta en la que colocas tus documentos de Numbers para ser compartidos.
En cuarto lugar, si quieres identificar dónde está la carpeta de iCloud con los documentos a compartir, desde dentro de AppleScript no la verás tal y como la ves desde el finder (es decir, en iCloud Drive), sino que tendrás que buscarla en /tuUsuario/Biblioteca/Documentos Móviles/iCloud Drive/tu carpeta.
Con todas estas advertencias, aquí está el script que estoy usando ahora. En mi sistema, funciona. Asume varias cosas:
- hay una carpeta en tu iCloud donde están tus documentos de Numbers
- tienes un archivo donde quieres guardar las rutas de los archivos que se van a compartir, para saber las rutas que tienes que comunicar a aquellos con los que quieres compartir tus archivos. En mi caso, uso un documento de Pages.
- los archivos a compartir NO ESTÁN ya compartidos. De lo contrario, el script dará errores.
- no te importan los errores ni el estilo. El script no tiene comprobaciones de errores. No soy programador.
El script te pedirá que identifiques primero la carpeta con los documentos a compartir, luego el archivo de Pages donde quieres guardar las rutas de los documentos compartidos, y después abrirá los documentos a compartir uno a uno, los compartirá, los guardará, copiará su ruta al documento de Pages que hayas seleccionado, y finalmente saldrá de Numbers y de Pages. Deja tiempo suficiente para que el scriptse ejecute y no interfieras en él. Fíjate en que al abrir cada archivo de Numbers, puedes modificar el script de forma que insertes las operaciones específicas que quieras que se hagan en tus archivos, siempre con la misma técnica (por ejemplo, en mi caso necesito buscar una celda, encontrar un valor, copiarlo en otro sitio y guardarlo. Esta parte del procedimiento no está en el script de abajo. Puedes añadir lo que tu fantasía te lleve a inventar como operaciones contorneadas y complicadas).
Ahora bien, si alguien encuentra una forma de REVERTIR la operación, despartiendo los archivos compartidos, y sobre todo, una forma de saber si un archivo está YA compartido o no, para que el script adquiera generalidad....
Pego el script a continuación.
-- Beginning of the script
global f
property extension_list : {"numbers"}
tell application "Finder"
set source_folder to choose folder with prompt "Please select directory."
set posixSource_Folder to POSIX path of source_folder
tell application "System Events"
set these_items to POSIX path of disk items of folder posixSource_Folder
end tell
my createList(these_items)
end tell
on createList(these_items)
tell application "System Events"
tell application "Finder"
set f to (choose file with prompt "Choose a file where to store the paths")
end tell
end tell
set posixF to POSIX path of f
delay 2
tell application "Finder" to open file f
delay 1
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set the item_info to info for this_item
set this_extension to the name extension of item_info
if folder of the item_info is true and (package folder of the item_info is false) and (this_extension is not in the extension_list) then
process_folder(this_item)
else
if (this_extension is in the extension_list) then
process_item(this_item)
end if
end if
end repeat
close_files()
end createList
-- this sub-routine processes folders
on process_folder(this_folder)
-- set these_items to list folder this_folder without invisibles
set posix_this_folder to POSIX path of this_folder
tell application "System Events"
set these_items to POSIX path of disk items of folder posix_this_folder
end tell
repeat with i from 1 to the count of these_items
--set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
set the item_info to info for this_item
set this_extension to the name extension of item_info
--if folder of the item_info is true and (this_extension is not in the extension_list) then
if folder of the item_info is true and (package folder of the item_info is false) and (this_extension is not in the extension_list) then
process_folder(this_item)
else
if (package folder of the item_info is true) and (this_extension is in the extension_list) and (alias of the item_info is false) then
process_item(this_item)
end if
end if
end repeat
end process_folder
-- this sub-routine processes files
on process_item(this_item)
set the item_info to info for this_item
set this_extension to the name extension of item_info
set this_package_folder to the package folder of item_info
set Posix_Item to POSIX path of this_item
set Posix_File to POSIX file Posix_Item
delay 1
--opening the Numbers file
tell application "Finder" to open Posix_File
delay 3
-- going to Numbers and making the file shared
tell application "System Events"
tell process "Numbers"
delay 1
tell menu bar 1
tell menu bar item "Share"
tell menu "Share"
delay 1
click menu item "Share Link via iCloud…"
end tell
end tell
end tell
end tell
-- extra time allowed for non packages
delay 3
end tell
if (this_package_folder is false) and (this_extension is in the extension_list) then
delay 30
end if
--tabs
tell application "System Events"
delay 1
key code 48
delay 1
key code 48
delay 1
-- arrows
key code 124
delay 1
key code 124
delay 3
-- returns
key code 36
-- leave some time for Numbers to actually share the file. Maybe you need more time for your system.
delay 8
-- saving and closing documents
keystroke "s" using {command down}
delay 4
keystroke "w" using {command down}
-- Now returning to the file where the paths have to be pasted
tell application "Finder" to open file f
delay 2
-- pasting the local Unix path
keystroke "v" using {command down}
delay 1
key code 48
delay 2
-- pasting the iCloud remote path of the shared document
set the clipboard to Posix_Item
delay 1
keystroke "v" using {command down}
delay 1
key code 48
key code 36
delay 1
keystroke "s" using {command down}
end tell
end process_item
--closing files
on close_files()
tell application "System Events"
tell process "Numbers"
tell menu bar 1
tell menu bar item "Numbers"
tell menu "Numbers"
delay 1
click menu item "Quit Numbers"
end tell
end tell
end tell
end tell
tell application "Finder" to open file f
delay 2
keystroke "q" using {command down}
delay 1
end tell
end close_files
-- end of the script