Re: Streamlining a script using the "Record" class
Re: Streamlining a script using the "Record" class
- Subject: Re: Streamlining a script using the "Record" class
- From: Andy Wylie <email@hidden>
- Date: Mon, 26 Nov 2001 10:08:10 +1300
on 22/11/01 7:36 AM, Eric Schult at email@hidden wrote:
>
I'm trying to demonstrate to a PC-centric audience how Applescript can
>
automate a task where Windows cannot. I've written an example script (below)
>
that checks the file type of every file in a folder and appends an
>
appropriate Windows suffix to the file name.
>
>
I know I could do this simpler by keeping the file types and related
>
suffixes in a record, but haven't worked much with the record class.
>
I though Christopher Stone provided an excellent RegEx solution to this
question on the Macscript list and I modified it so...
-------------------------
--Requires Akua Sweets and RegEx OSAX
-------------------------
property typeSufx : "
EPSf == .eps
EPSp == .eps
TEXT == .txt
JPEG == .jpg
GIFf == .gif
PICT == .hah
"
set xlst to the entries in (choose folder) whose kinds are file to a depth
of -1 as alias
repeat with i in xlst
set theInfo to basic info for i
set {type, fileName} to {((theInfo)'s file type), ((theInfo)'s name)}
set suffix to REMatch typeSufx pattern (type & " == (.+)") using "\\1"
if (suffix is not false) and (text -1 thru -4 of fileName) is not suffix
then
if (count of fileName) < 27 then
collate {file ("" & i)} by renaming it to (fileName & suffix)
else
collate {file ("" & i)} by renaming it to ((text 1 thru 27 of
fileName) & suffix)
end if
end if
end repeat
-------------------------
>
I don't want to scare folks away from learning this if I can help it. Can
>
anybody lend a hand with this or other simplification suggestions?
OSAX! the Finder approach gets scarey real fast...
set x to choose folder
tell application "Finder"
if (count of every file of alias x) > 1 then
set thesel to (every file of x) as alias list
else
set thesel to {} & ((every file of x) as alias)
end if
end tell
...milli vanilli ad nauseum
_________________________Andy