Re: Getting file suffix
Re: Getting file suffix
- Subject: Re: Getting file suffix
- From: Ronald Hofmann <email@hidden>
- Date: Tue, 14 Sep 2010 16:39:24 +0200
> This is what I ended up with though, which I think will be safest in all cases:
What do you mean by this?
Do you assume the Finder´s 'info for' will some day not work the same way it is doing now???
But you assume that 'text item delimiters' will always work?
This is strange. Do you distrust functions generally?
What you do is just a workaround for somebody who doesn´t know the finders 'info for.
On the other hand, your workaround might not work anymore someday when things change.
But Finder functions will surely adopt to such changes.
Your handler delivers for my artifical file "MacOSX:Users:ronny:Desktop:myFile.honeypot" the extension 'honeypot'. This is the same what the Finder does. What obviously is wrong. May be there is someday a change in MacOSX to recognize correct extensions. But than your handler will still fail while 'info for' will do alright.
My proposal:
set thePath to choose file with prompt "Choose File please..."
set theSuff to getSuffix(thePath)
on getSuffix(thePath)
tell application "Finder"
return (name extension of (info for thePath))
end tell
end getSuffix
Greetings, Ronald
---
Am 14.09.2010 um 16:03 schrieb LuKreme:
> 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
>
> -- this_item is an alias in the after receiving list of the folder action
> set item_suffix to getSuffix(this_item)
>
> Which I think has the benefit that it's always going to work, regardless of if the finder gets the extension name or not.
>
>> So to sum up: if your extensions are sufficiently Finder-friendly, you
>> can just ask the Finder for them. If not, be sure to de-pathify the
>> string first (split on colons or ask the Finder for an alias's "name")
>> before looking for the period, and be sure to handle the case where
>> there isn't one.
>
> Thanks for everyone's comments.
>
> --
> Demons have existed on the Discworld for at least as long as the gods,
> who in many ways they closely resemble. The difference is basically the
> same as between terrorists and freedom fighters. --Eric
>
> _______________________________________________
> 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
_______________________________________________
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