Sorry if I ask the fundamental question, I’m new with Applescript.
I have a path of a document contains extension, how can I cut off the extension or generally modify the string as we do with strncpy() ? I need to be able to cut from nth char to (n+x)th char of string to make a new string.
This on simply divides the text into two list items (the file name and the extension) and returns the first item only.
Any string with dots in will be split into items.
set mystring to "myfile.txt"
set mystring to my strip_ext(mystring)
display dialog mystring
on strip_ext(mystring)
set AppleScript's text item delimiters to "."
set the item_list to every text item of mystring
return the first item of item_list
end strip_ext
I like this approach, where choose file is substituted for an alias to your file (I’m assuming you want just the name and not the rest of the path without the extension):
tell (info for (choose file)) to set basename to name's text 1 thru ((my (offset of ("." & name extension) in name)) - 1)