I have a list called num. I have converted it into a string. I want to return that string so that the next action called "New text file" in my automator workflow can get the string. This is my code -
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
It doesn't return anything.
EDIT: As some of you have asked. I am going to elaborate on the question. My automator workflow, takes some parts of some text in an email, it retrieves all the phone numbers in the group which is specified in the text of the email, and stores them in a text file.
the variable 'cat' has the list of contact groups
This is the full code:
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
This code is supposed to be followed by a 'new text file' action which should take the output of the previous action ('run applescript') as input. That doesn't happen as for some reason, applescript refuses to return the value even when I am getting the desired value when using 'display dialog'.
UPDATE: I am now posting the entire workflow
Input- In mail app - An email with this content - "#a, #b Q: this is a question for all of you."
Workflow -
1) Run Applescript Code -
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) Set Value of Variable
Sets the output of previous action to 'cat'
3) Run Applescript
on run {input, parameters}
tell application "Mail" to set theMessageText to content of (get first message of inbox)
end run
4) New Mail Message
Appends the text from previous action to the bod of email
5) Run Applescript
The code that @Tetsujin gave in the answers
6) New Text File
7) Add attachments to front message
8) Send Outgoing Messages
9) Run Applescript (Deletes the email)
Code -
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
{input, parameters}
and run the code in Applescript Editor, it spits out1\n2
. You should say exactly what you're trying to automate and what you've done so we can fully understand the problem.