MACSCRPT Archives

January 2011

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Mark J. Reed" <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Thu, 20 Jan 2011 09:12:01 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (25 lines)
On Thu, Jan 20, 2011 at 4:30 AM, Claudio Braga <[log in to unmask]> wrote:
> removing the extension of the filename, any tricks to do this in the best way? Given that there are no out-of-the-box commands for this, do I just have to play with strings, looking for a . from the right etc.? looks a bit 'unprofessional'....

Well, if you need the extension, you can get it this way:

name extension of (info for someFile)

but if you want the filename with the extension removed, you're pretty
much stuck with string manipulation.  (Or else tricks where you tell
the Finder  not to include extensions and then ask it for the name,
but that's slow and hacky.)

You may find it less "unprofessional" to use the value of the name
extension to guide the manipulation, instead of using text item
delimiters or similar.  For example:

tell (info for someFile)
    set {theName, theExtension} to {name, name extension}
end
set bareName to text 1 through -(length of theExtension + 2) of theName


-- 
Mark J. Reed <[log in to unmask]>

ATOM RSS1 RSS2