The Perplexing PROBLEM is spacing between variables output. I would like it to come out like:
Out of Town Feng Bach Lund Yeh Rizea Schandelmeier Barger
but it comes out:
Out of Town FengBachLundYehRizeaSchandelmeierBarger
and I manually seperate the names which is a hassle.
set OutOfTown to "Out of Town " as text -- new variable that stores text to differentiate reason off call schedule 00T=Out of Town
set OOTDate to text (item 1 of OOTData & "," & item 2 of OOTData) as date
set OOTTime to (item 2 of OOTData)
set OutOfTownEqualsY to (item 3 of OOTData)
set Feng to (item 4 of OOTData) -- who is out of town
set Lund to (item 5 of OOTData) -- who is out of town
set Bach to (item 6 of OOTData) -- who is out of town
set Yeh to (item 7 of OOTData) -- who is out of town
set Rizea to (item 8 of OOTData) -- who is out of town
set Schandy to (item 9 of OOTData) -- who is out of town
set Barger to (item 10 of OOTData) -- who is out of town
set OutOfTownProviders to (Feng & Lund & Bach & Yeh & Rizea & Schandy &
Barger) as text
if (OutOfTownEqualsY is equal to "Y") then -- checks for Y in 3rd column of csv to determine if anyone is OOT
set WhoIsOutOfTown to (OutOfTown & OutOfTownProviders) as text -- define combined data as text and puts it into variable WhoIsOutOfTown
-- it to iCal's event n class summary property (unicode text) below
else if (OutOfTownEqualsY is not equal to "Y") then
set WhoIsOutOfTown to (item 3 of OOTData) as text -- sets variable WhoIsOutOfTown to 7:00 AM if nobody is out of town
end if
Thank you for assisting me with this problem.
Sincerely Gschandy
Model: Dual 1.8 Mhz G5
AppleScript: 1.10.6
Browser: Safari 417.9.3
Operating System: Mac OS X (10.4)
set OutOfTownProviders to (Feng & Lund & Bach & Yeh & Rizea & Schandy &
Barger) as text
set WhoIsOutOfTown to (OutOfTown & OutOfTownProviders) as text -- define combined data as text and puts it into variable WhoIsOutOfTown
Hi Gschandy,
The above lines are what set the string. The 1st one takes the seperate names and joins (concatenate) them together. It’s putting them together without spaces. You change that to
set OutOfTownProviders to (Feng & space & Lund & space & Bach & space & Yeh & space & Rizea & space & Schandy & space & Barger
set WhoIsOutOfTown to (OutOfTown & space & OutOfTownProviders)
For a while, I was using scripts I found. It was only recently that I started to write my own. I’m finding AppleScript very interesting and fun, and not impossible to learn. Like the above changes, not too bad huh?
There’s lots of resources on this site to help you continue. Good luck.
Wow Great gyuen,
That does it. Your right I was very happy to work this script out with applescript from an open source resoure script. Here is the complete modified open source script for anyone making a vacation schedule for up to seven people in iCal.
Thanks again gyuen
Here’s another example of a way to change a list of string to string with delimiter instead of typing all the spaces.
set l to {“a”, “b”, “c”}
set def_tid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {space}
set t to l as string
set AppleScript’s text item delimiters to def_tid
return t
Excellent kel. I knew it went something like that though I would have had to read and experiment for at least a few minutes to figure that out.
As a handler for reuse:
set string1 to "Hey,"
set string2 to "this"
set string3 to "works!"
set newString to my combineTogether({string1, string2, string3})
display dialog newString
on combineTogether(myList)
set l to myList
set def_tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {space}
set t to l as string
set AppleScript's text item delimiters to def_tid
return t
end combineTogether
You could make the handler even more versatile by specifying different delimiters in the calling statement - perhaps something like this:
to make_text from l around s
set d to text item delimiters
set text item delimiters to s
set l to l as text
set text item delimiters to d
l
end make_text
display dialog (make_text from {"Here", "are", 1, "or", 2, "examples", "of", "making", "text", "from", "a", "list..."} around space)
set pet_list to {"cat", "dog", "hamster", "mouse", "elephant", "budgerigar", "parrot", "vulture", "goldfish", "whale"}
display dialog "Is your pet a " & (make_text from pet_list's items 1 thru -2 around ", ") & " or " & pet_list's item -1 & "?"
set shopping_list to {"bread", "milk", "eggs", "MacBook Pro", "cheese", "poatoes", "Lamborghini Countach", "butter"}
display dialog "My Shopping List:" & return & return & (make_text from shopping_list around return)
I wasn’t sure how to iterate a range if items in a list. I’m was using code like “2 thru (count of items in thisList)”. Though “2 thru end” isn’t right; maybe it’s “2 thru 0”?
Lists know how to count backwards, and you can use “last item” as well. The last item is item -1, the next to last is item -2, etc. The range from second item to second to last item is 2 thru -2.
These are called “range references” and there is an excellent article by Nigel Garvey on Range References here
In fact, Gary, your experiments really only lacked a specification of the object class to be listed. Since, in this case, we’re extracting from a list (and we’re not trying to filter items of any particular class), we should ask for ‘items’.
The pet_list example above actually contains an example of this. Here’s how it works:
to make_text from l around s
set d to text item delimiters
set text item delimiters to s
set l to l as text
set text item delimiters to d
l
end make_text
set pet_list to {"cat", "dog", "hamster", "mouse", "elephant", "budgerigar", "parrot", "vulture", "goldfish", "whale"}
(* define the list to be referenced and attribute values to it *)
make_text from pet_list's items 1 thru -2 around ", "
(* that's: every item of pet_list, from the first to the second to last item - separated by a comma/space *)
--> "cat, dog, hamster, mouse, elephant, budgerigar, parrot, vulture, goldfish"
"Is your pet a " & result & " or " & pet_list's item -1 & "?"
(* concatenate the strings: ["Is your pet a "] & [the above text] & [" or "] & [last item of pet_list] & ["?"] *)
--> "Is your pet a cat, dog, hamster, mouse, elephant, budgerigar, parrot, vulture, goldfish or whale?"
(* then just display the result in a dialog *)
display dialog result
I’d echo Adam’s advice that Nigel’s enlightening article is well worth reading. Not only does Mr G. know this stuff inside out, but he puts it across so well.