1 Reply Latest reply on Jul 8, 2008 3:36 PM by sstanleyau

    Unicode problem

      This script is supposed to insert a character but instead it inserts characters Unicode value in brackets (like this <0022>).

      What might be wrong?

      tell application "Adobe InDesign CS3"
      
      set myDoc to active document

      set myParaList to name of every paragraph style of myDoc
      set myDialog to make dialog with properties {name:"Paragraph Styles"}
      tell myDialog
        tell (make dialog column)
         tell (make border panel)
          tell (make dialog column)
           make static text with properties ¬
            {static label:"Choose a paragraph style to affect", min width:150}
          end tell
          tell (make dialog column)
           set myPresetsDropdown to make dropdown with properties ¬
            {string list:myParaList, selected index:0, min width:150}
          end tell
          tell (make border panel)
           tell (make dialog column)
            make static text with properties {static label:"Character :"}
           end tell
           tell (make dialog column)
            -- edit contents must be unicode string
            set myAddChar to make text editbox with properties {edit contents:"000D", min width:100}
           end tell
          end tell
         end tell
        end tell
      end tell
      set myResult to show myDialog
      if myResult = true then
        -- +1 gets the correct name because list starts at 0
        set myPara to item ((selected index of myPresetsDropdown) + 1) of myParaList
        set myChar to edit contents of myAddChar as string
      end if
      destroy myDialog

      set theStories to object reference of stories of myDoc
      repeat with theStory in theStories
        try
         set theParaStyles to name of applied paragraph style of object reference of paragraphs of theStory
         repeat with x from 1 to (count of theParaStyles) - 1
          if myPara = contents of item x of theParaStyles then
           applyPara(x, theStory, myChar) of me
          end if
         end repeat
        end try
      end repeat
      end tell

      on applyPara(paraNum, storyRef, myChar)
      tell application "Adobe InDesign CS3"
        set myCodeToInsert to "<" & myChar & ">"
        repeat
         set contents of insertion point 1 of paragraph paraNum of storyRef to myCodeToInsert
         exit repeat
        end repeat
      end tell
      end applyPara
        • 1. Re: Unicode problem
          sstanleyau Level 4
          My guess is that you're using OS X 10.5.x. As of 10.5, all AppleScript text<br />is Unicode, so when you pass "<0022>" to InDesign, it sees that it's Unicode<br />already and thus doesn't try to convert it to a Unicode character.<br /><br />The solution is to do the conversion yourself. You'll need to convert the<br />value from hexadecimal to decimal (or have the user enter it that way in the<br />first place), and then use something like:<br /><br />    set myCodeToInsert to character id (myChar as integer)<br /><br />That needs to be outside a 'tell app "InDesign"' block.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au>