Tengo una lista llamada num. La he convertido en una cadena. Quiero devolver esa cadena para que la siguiente acción llamada "Nuevo archivo de texto" en mi flujo de trabajo de Automator pueda obtener la cadena. Este es mi código
on run {input, parameters}
set num to {1,2}
set f to ""
repeat with x in num
set f to f & x & "\n"
end repeat
return f
end run
No devuelve nada.
EDIT: Como algunos de vosotros habéis preguntado. Voy a ampliar la pregunta. Mi flujo de trabajo de Automator, toma algunas partes de un texto en un correo electrónico, recupera todos los números de teléfono en el grupo que se especifica en el texto del correo electrónico, y los almacena en un archivo de texto.
la variable "cat" tiene la lista de grupos de contacto
Este es el código completo:
on run
set cat to value of variable "cat" of front workflow (*I have already defined the variable elsewhere in the workflow*)
set num to {}
set f to ""
tell application "Contacts"
repeat with i in cat
set inGroup to group i
set phoneProps to value of phones of inGroup's people
set end of num to first item of first item of phoneProps
end repeat
end tell
repeat with x in num
set f to f & x & "\n"
end repeat
return f
end run
Se supone que este código va seguido de una acción "nuevo archivo de texto" que debería tomar la salida de la acción anterior ("ejecutar applescript") como entrada. Esto no sucede ya que por alguna razón, applescript se niega a devolver el valor incluso cuando obtengo el valor deseado al utilizar el "diálogo de visualización".
ACTUALIZACIÓN: Ahora estoy publicando el flujo de trabajo completo
Entrada - En la aplicación de correo - Un correo con este contenido - "#a, #b P: esta es una pregunta para todos ustedes".
Flujo de trabajo -
1) Ejecutar Applescript Código -
on run {input, parameters}
tell application "Mail" to set theMessageText to content of (get first message of inbox)
set topic to text ((offset of "#" in theMessageText) + 1) thru ((offset of "Q" in theMessageText) - 1) of theMessageText
set AppleScript's text item delimiters to ", "
set bowords to words of topic
set o to length of bowords
repeat with i from 1 to o
trim_line(bowords, "#", 0)
end repeat
bowords
end run
on trim_line(this_text, trim_chars, trim_indicator)
set x to the length of the trim_chars
-- TRIM BEGINNING
if the trim_indicator is in {0, 2} then
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the trim_indicator is in {1, 2} then
repeat while this_text ends with the trim_chars
try
set this_text to characters 1 thru -(x + 1) of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return this_text
end trim_line
2) Establecer el valor de la variable
Establece la salida de la acción anterior como 'cat'
3) Ejecutar Applescript
on run {input, parameters}
tell application "Mail" to set theMessageText to content of (get first message of inbox)
end run
4) Nuevo mensaje de correo
Añade el texto de la acción anterior al cuerpo del correo electrónico
5) Ejecutar Applescript
El código que @Tetsujin dio en las respuestas
6) Nuevo archivo de texto
7) Añadir archivos adjuntos al mensaje frontal
8) Enviar mensajes salientes
9) Ejecutar el Applescript (Borra el correo electrónico)
Código -
on run {input, parameters}
delay (10)
tell application "Mail"
set theMessages to (get selection)
repeat with eachMessage in theMessages
set theAccount to account of (mailbox of eachMessage)
move eachMessage to mailbox "Trash" of theAccount
end repeat
end tell
return input
end run