• 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: Getting file suffix
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting file suffix


  • Subject: Re: Getting file suffix
  • From: KOENIG Yvan <email@hidden>
  • Date: Tue, 14 Sep 2010 16:50:13 +0200

Le 14 sept. 2010 à 16:03, LuKreme a écrit :

>
> On 13-Sep-2010, at 07:42, Mark J. Reed wrote:
>>
>> André told you how in the very next line of his message:
>>
>> tell app "Finder" to get the name extension of thisFile
>
> Doh.
>
>> But as Luther pointed out, the Finder is somewhat picky about what it
>> considers a "name extension"; any old string of characters after a
>> period doesn't quite cut it.
>
> I'd actually assumed that the finder extension name would not work since the files I was testing by default were .nzb and .torrent, which I expected were rather non-standard extensions. However, Finder seems to return them just fine.
>
> This is what I ended up with though, which I think will be safest in all cases:
>
> on getSuffix(myFile)
> tell application "Finder" to set myFile to name of myFile
> if myFile contains "." then
>   set oldDelims to AppleScript's text item delimiters
>    set AppleScript's text item delimiters to "."
>    set theSuffix to last text item of myFile
>    set AppleScript's text item delimiters to oldDelims
>    return theSuffix
>  end if
> end getSuffix

Always the same oddity.

As you may use the instruction :
> tell application "Finder" to set myFile to name of myFile

it's clear that myFile is not a text object.

So, the instruction :
> set theSuffix to last text item of myFile

will fail.

Would be useful to edit  the handler this way :

on getSuffix(myFile)
tell application "Finder" to set myFile to name of myFile
set myFile to ""&myFile (* coerce the file reference to a text object *)
if myFile contains "." then
  set oldDelims to AppleScript's text item delimiters
   set AppleScript's text item delimiters to "."
   set theSuffix to last text item of myFile
   set AppleScript's text item delimiters to oldDelims
   return theSuffix
 end if
end getSuffix


which I would edit more as :


on getSuffix(myFile)
tell application "Finder" to set myFile to name of myFile
set myFile to ""&myFile (* coerce the file reference to a text object *)
if myFile contains "." then
  set oldDelims to AppleScript's text item delimiters
   set AppleScript's text item delimiters to "."
   set theSuffix to last text item of myFile
   set AppleScript's text item delimiters to oldDelims
else
set theSuffix to ""
end if
   return theSuffix
end getSuffix

Without that, the instruction

set the_suffix to my getSuffix(a_file_with_no_suffix)
will give you "the_suffix is not defined"

Yvan KOENIG (VALLAURIS, France) mardi 14 septembre 2010 16:50:05



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Getting file suffix
      • From: LuKreme <email@hidden>
References: 
 >Re: Getting file suffix (From: Shane Stanley <email@hidden>)
 >Re: Getting file suffix (From: LuKreme <email@hidden>)
 >Re: Getting file suffix (From: "Mark J. Reed" <email@hidden>)
 >Re: Getting file suffix (From: LuKreme <email@hidden>)

  • Prev by Date: Re: AppleScript-Users Digest, Vol 7, Issue 461
  • Next by Date: Re: Finder 'desktop position' bug
  • Previous by thread: Re: Getting file suffix
  • Next by thread: Re: Getting file suffix
  • Index(es):
    • Date
    • Thread