Re: File extensions & Displayed names
Re: File extensions & Displayed names
- Subject: Re: File extensions & Displayed names
- From: Timothy Bates <email@hidden>
- Date: Wed, 06 Feb 2002 12:04:45 +1100
This is my take, but it exposes a Finder bug: you can't set the <extension
visible> of a file to false by script, even when you can manually.
The solution to all of this is for the Finder file object to have a
"non-extended name" property as well as "name extension" (which is good) and
displayed name (which is ambiguous 'cause it might contain the suffix or
might not depending on the hidden settings) and the name (which always
contains everything and could just be parsed like we used to do)
Anyhow, here's the handler
set x to "Cortex:audio movie.scpt"
set suffix to " blah"
rename(x, suffix)
on rename(x, suffix)
tell application "Finder"
set x to file x
if name extension of x = "" then
set name of x to (displayed name of x & " suffix")
else
set humanName to text 1 thru ((offset of (name extension of x [break]
as string) in (name of x as string)) - 2) of (name of x as string)
set newFullName to (humanName & suffix & "." & name [break]
extension of x as string)
set {name of x, extension hidden of x} to [break]
{newFullName, extension hidden of x}
end if
end tell
end rename
On 6/2/02 12:34 AM, "Mr Tea" <email@hidden> wrote:
>
This makes renaming files with applescript an onerously complex business
>
where any kind of name extension is involved. Preserving name extensions
>
and retaining their hidden or unhidden state would seem to require
>
something like this:
>
on open {x}
>
tell application "Finder"
>
activate
>
set theExtn to name extension of x as string
>
if extension hidden of x is true then
>
set hideExt to true
>
else
>
set extension hidden of x to true
>
set hideExt to false
>
end if
>
if theExtn is not "" then
>
set name of x to (displayed name of x & " suffix" & "." & theExtn)
>
else
>
set name of x to (name of x & " suffix")
>
end if
>
if hideExt then set extension hidden of x to true
>
end tell
>
end open
>
>
Preposterous is the word that springs to mind. And sluggish too. Can
>
anyone suggest a faster and significantly more concise way to achieve the
>
same thing?
>
>
>
Mr Tea
Dr Timothy Bates <
mailto:email@hidden>
Macquarie Centre for Cognitive Science (MACCS)
Macquarie University
Ph 61 (2) 9850 8623
Fx 61 (2) 9850 6059