Displaying truncated text in text field

In the UI of my application, I have a text field which displays a file path chosen by the user. Sometimes this file path is going to be too long for the space available. The file path may be -


What I want, if it’s too long for the length of the text field, is to look something like this -


and then displays the full path in that cute yellow panel when the cursor is held over it.

Is this possible in AppleScript Studio?

Do you want the user to be able to directly edit the path, or are you using a button to display a ‘choose folder’ dialog, and then putting the result in a non-editable text field?

The latter.

The text field is non-editable. The path returned by ‘choose folder’ is stored in a variable elsewhere, and what’s displayed in the UI is just for confirmation that this is the folder they chose.

In Interface Builder, add one of the text fields that say ‘System Font’ or ‘Label Font’, and then use the Inspector to change the ‘Line Breaking’ to ‘Truncate Middle’. Note that using the input-style text field will not allow you to choose this option. However, if you want to break the text in the middle and still have the text field appear as a disabled input-style text field, it can be configured by following these steps (using the Inspector):

  • Change the text border to the rightmost option.
  • Click on Background Color.
    • If necessary, choose the Color Palettes pane, and then choose Developer.
  • In the color picker, choose ‘controlBackgroundColor’.
  • Click on Text Color.
  • In the color picker, choose ‘disabledControlTextColor’.

Thanks Bruce.

There’s a small snag. I’m still using Interface Builder 2.4.2 (v364) with OS 10.3.8. It seems that Line Break controls weren’t there until 2.5 and OS 10.4.

However you did show me something about the color pallete I didn’t know.
I’ll just have do it using Cocoa and ObjC.
It’s amazing how much work these details can be.