Author Topic: Q8 AppScp: keep punctuation (parens) with "words"  (Read 1346 times)

0 Members and 1 Guest are viewing this topic.

Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
Q8 AppScp: keep punctuation (parens) with "words"
« on: April 09, 2009, 09:00:09 PM »
ok. i'm making some progress here, but didnt want to get stuck on this one for the weekend...

basically i have to get a number of variables out of the Layout Properties Name.
this works... EXCEPT... it loses the parens around any of the words. i dont know how to keep punctuation. the command is  "words".

also, dont know if this is relevant /helpful, but i can predict what the words will be (most of the time)... for example. i could say:

if company1 contains "stripe" then put "(" before (the word before "stripe)  and ")" after (the word "stripe") [as in (blue stripe) or (red stripe)]

but this (obviously) isnt code, its just an explanation. it would be preferable to just keep parens.

any help would be most welcome and appreciated.
m./

tell layout space 1 of project 1
      set company1 to name as string
      set s to the count of words in company1      
      -- --------------------------------------------------------------------      
      -- split out the name, description and proof no.
      -- --------------------------------------------------------------------
      set AppleScript's text item delimiters to space
      set cn to (words 1 thru (s - 2) of company1) as string
      set proofno to (words -2 thru -1 of company1) as string
      set AppleScript's text item delimiters to {}


Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: Q8 AppScp: keep punctuation (parens) with "words"
« Reply #1 on: April 10, 2009, 02:39:19 AM »
the problem you have here is using words. Applescript sees words as very specific character sets and will not include brackets.
You will need to use text items instead. So your code becomes;

-- --------------------------------------------------------------------     
-- split out the name, description and proof no.
-- --------------------------------------------------------------------
set ATID to AppleScript's text item delimiters
set s to count of text items in company1
set AppleScript's text item delimiters to space
set cn to (text items 1 thru (s - 2) of company1) as string
set proofno to (text items -2 thru -1 of company1) as string
set AppleScript's text item delimiters to ATID

A little tip here. If you are using Applescript's text item delimiters capture them first and reset to what they were previously. In this way you will not be caught out when you have nested code or functions.

Offline 4610036

  • Jr. Member
  • **
  • Posts: 50
  • Karma: 0
  • Gender: Female
[SOLVED] Re: Q8 AppScp: keep punctuation (parens) with "words"
« Reply #2 on: April 10, 2009, 05:56:30 AM »
thank you thank you!

that works perfectly now!
previously, i played with "items" but not text items -- and was just doing it wrong.
and i like the way u define the delimeters.
nice!
u saved me lots of circling and aimless code. much much appreciated.
m./