Text bolding help

I am very new to applescript and am trying to create a script to run in Quark that will take text from the clipboard and put it into a selected text box. The catch is that the text in the clipboard will have words in it that have brackets (ex. “[ aword]”)[applescript around them that need to be made bold and the brackets removed. I have come up with the following code so far. It is one of my first attempts so be gentle and thank you so much for any help!


tell application "QuarkXPress" 
  -- open quarkxpress if it is not open 
  activate 

  -- make sure there is a document open 
  if (exists (document 1)) then 
    -- pull the information from the clipboard 
    set theclip to the clipboard 

    tell document 1 to set story 1 to theclip 

    -- initialize the brace holders 
    set brace1 to 1 
    set brace2 to 1 
    set brace1offset to 1 
    set brace2offset to 1 

    repeat while brace1offset > 0 
      tell application "Finder" 
        set brace1offset to (offset of "[" in (characters brace1 thru (length of theclip) of theclip) as string) 
        set brace2offset to (offset of "]" in (characters brace2 thru (length of theclip) of theclip) as string) 
        set brace1 to brace1 + brace1offset 
        set brace2 to brace2 + brace2offset 
      end tell 

      if brace1offset > 0 then 
        tell document 1 to set style of characters (brace1 + 1) thru (brace2 - 2) of story 1 to bold 
      end if 
    end repeat 
  else 
    display dialog "You must have a window open" buttons {"I Am Stupid"} default button 1 
  end if 
end tell 

I don’t know anything about Quark, so can’t help you with bolding, but AppleScript can deal with getting rid of the brackets:


set tClip to "[ word_1] [word_2]" -- just a sample of what might be there

-- set tClip to the clipboard -- how you get it for real

set tid to AppleScript's text item delimiters -- remember the old values (normally "")
set AppleScript's text item delimiters to "]" -- grab one end
set clip to text items of tClip -- get the pieces
set AppleScript's text item delimiters to tid -- set 'em back
set tWords to {} -- a place to store results
repeat with anItem in clip -- grind through all the words
	if contents of anItem is not "" then set end of tWords to text 2 thru -1 of anItem
end repeat
--> {" word_1", "word_2"}

Of course, you could have found the near “[”, and then grabbed text 1 thru -2 of anItem - doesn’t matter.
The check for an empty item is because when the delimited text is first or last, it shows in the text items as “”

You might be tempted to use this:



set tClip to "[ word_1] [word_2]" -- just a sample of what might be there

-- set tClip to the clipboard -- how you get it for real

set W to words of tClip -- this is quite simple, but it will miss the leading space in the first word, and spaces between them so you want to target the brackets specifically.