• 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
Streamlining a script using the "Record" class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Streamlining a script using the "Record" class


  • Subject: Streamlining a script using the "Record" class
  • From: Eric Schult <email@hidden>
  • Date: Wed, 21 Nov 2001 12:36:11 -0600

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 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?

Any help greatly appreciated.


WES


P.S. - Watch for the <option-return> characters ( , ) below!



set myFolder to choose folder with prompt "Select a folder." as string

tell application "Finder"
activate
set fileList to name of every file in folder myFolder
repeat with i from 1 to count of items in fileList
set fileType to file type of file (myFolder & ,
(item i in fileList) as string)
if fileType is "GIFf" then
if item i in fileList does not end with ".gif" then
try
set name of file (myFolder & (item i in fileList) as string) to ,
(item i in fileList & ".gif" as string)
on error
display dialog "Couldn't rename file \"" & ,
(item i in fileList) & "\"" & " to " & ,
((item i in fileList) & ".gif")
end try
end if
else if ((fileType is "EPSf") or (fileType is "EPSp")) then
if item i in fileList does not end with ".eps" then
try
set name of file (myFolder & (item i in fileList) as string) to ,
(item i in fileList & ".eps" as string)
on error
display dialog "Couldn't rename file \"" & ,
(item i in fileList) & "\"" & " to " & ,
((item i in fileList) & ".eps")
end try
end if
else if fileType is "PDF " then
if item i in fileList does not end with ".pdf" then
try
set name of file (myFolder & (item i in fileList) as string) to ,
(item i in fileList & ".pdf" as string)
on error
display dialog "Couldn't rename file \"" & ,
(item i in fileList) & "\"" & ,
" to " & ((item i in fileList) & ".pdf") with note caution ,
giving up after 5
end try
end if
else if fileType is "JPEG" then
if item i in fileList does not end with ".jpg" then
try
set name of file (myFolder & (item i in fileList) as string) to ,
(item i in fileList & ".jpg" as string)
on error
display dialog "Couldn't rename file \"" & ,
(item i in fileList) & "\"" & ,
" to " & ((item i in fileList) & ".jpg")
end try
end if
end if
end repeat
end tell

beep 2


  • Follow-Ups:
    • Re: Streamlining a script using the "Record" class
      • From: Matthew Smith <email@hidden>
    • Re: Streamlining a script using the "Record" class
      • From: Andy Wylie <email@hidden>
    • Re: Streamlining a script using the "Record" class
      • From: Jason Bourque <email@hidden>
  • Prev by Date: Re: ANNOUNCE: XML Tools 2.3.2
  • Next by Date: [Fwd: OS 9.1 or AppleScript problem?]
  • Previous by thread: FTP Uploads using URL Access Scripting
  • Next by thread: Re: Streamlining a script using the "Record" class
  • Index(es):
    • Date
    • Thread