• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: text item delimiters maddness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: text item delimiters maddness


  • Subject: Re: text item delimiters maddness
  • From: Andrew Oliver <email@hidden>
  • Date: Mon, 03 Feb 2003 12:23:28 -0800

Assuming this is the same question as posted on Apple's Discussion Boards
(which begs the questions why the discussion boards and the list aren't
linked...?)

Specifically, you're using "words 1 through -3"

'words' uses language-specific definitions of what constitutes a 'word',
including hyphenation, underscores, punctuation, etc.

Instead, you should use 'text items' to arbitrarily break a string based on
a specific character:

set thePath to "Drive:Folder:Folder with
spaces:or_underscores:Folder:filename"
set oldDelims to AppleScript's text item delimiters -- save the current
delimiter
set AppleScript's text item delimiters to ":"
set conDir to (text items 1 through -3 of thePath) as string
--> "Drive:Folder:Folder with spaces:or_underscores"
set AppleScript's text item delimiters to oldDelims -- make sure we restore
the TIDs

Alternatively, though, and to be sure, you can also use the Finder's
dictionary to get a path:

tell application "Finder"
set sceneFile to (choose file)
set conDir to (container of sceneFile) as string
end tell

This is the preferred method for tracking files since it uses the System's
understanding of directories and filenames.

Andrew
:)

On 2/3/03 11:06 AM, "James Burns" <email@hidden> wrote:

> Hello:
>
> Today I have a question about how to properly extract select chunks
> from a path, to truncate it to a certain length. Here's what I was
> using:
>
> set fileContents to read file sceneFile -- read chosen file
> set text item delimiters to ":"
> set conDir to ((words 1 thru -3 of sceneFile) as string) & ":" --
> figure out content directory
>
> ... and this works fine for most files, except those that have the
> underscore character in them.
>
> Thus, a path of:
>
> "TiBook1:Documents:jpb Projects:News24 Houston:scenes:News24in_02.lws"
>
> becomes:
>
> "TiBook1:Documents:jpb:Projects:News24:Houston:scenes:News24in:_:"
>
> Any clever thoughts out there? Thanks in advance...
>
> -----
> James Burns
> http://www.jamesburnsdesign.com
> _______________________________________________
> applescript-users mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/applescript-users
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >text item delimiters maddness (From: James Burns <email@hidden>)

  • Prev by Date: text item delimiters maddness
  • Next by Date: Re: Mail Action Message Source Encoding Difficulty
  • Previous by thread: text item delimiters maddness
  • Next by thread: Re: text item delimiters maddness
  • Index(es):
    • Date
    • Thread