Ignoring Command

I am trying to get applescript to select the name of a Quark EPS file with some conditions. Sometimes the file name begins with two spaces and then the name. I want applescript to ignore the two spaces.

We use the following to select the file name when the spaces ARE NOT present:

set epsNameTrunc to ((characters 1 thru epsNameCount of the epsName) as string)
set epsNameTruncTrunc to ((characters 1 thru 8 of the epsNameTrunc) as string)
set epsNameTruncTruncTxt to epsNameTruncTrunc as string

As you can see we are only after 8 of the characters of the name. The name has more than 8 characters at times so we need to select only the 8 se need.

I thought I would use “ignoring white space” to select the proper characters when the file name begins with the two spaces. Maybe this is not the right approach?

Can anyone solve this for me.

Thanks in advance.
Dean

I don’t think ‘ignoring white space’ will help you here. This should do it with most file names:

set epsNameTrunc to text from word 1 to end of epsName
if (count epsNameTrunc) > 8 then set epsNameTrunc to text 1 thru 8 of epsNameTrunc

But in case a file name should happen to begin with some character that AppleScript doesn’t consider part of a word, this would be safer:

set i to 1
repeat while character i of epsName is space
  set i to i + 1
end repeat

if (count epsName) - i > 7 then
  set epsNameTrunc to text i thru (i + 7) of epsName
else
  set epsNameTrunc to text i thru end of epsName
end if

Hi :slight_smile:
Here another suggestion with the AppleScript’s text items delimiters:

set NameClean to my CleanName("  Name of my QXP Doc", 8, "  ")
--> "Name of "
on CleanName(NameDoc, LengthName, TxtToClean)
	set AppleScript's text item delimiters to TxtToClean
	set NameDocLst to text items of NameDoc
	set AppleScript's text item delimiters to ""
	set NameDocTxt to (text 1 thru end of (NameDocLst as text))
	if (length of NameDocTxt) > LengthName then ¬
		return text 1 thru LengthName of NameDocTxt
	return NameDocTxt
end CleanName

:wink:

Thanks for the help. I managed to accomplish my task by simply having AppleScript “choose the first 8 characters of the first word”

Works for me.