Re: Manipulating multiple files in arbitrary applications
Re: Manipulating multiple files in arbitrary applications
- Subject: Re: Manipulating multiple files in arbitrary applications
- From: "Marc K. Myers" <email@hidden>
- Date: Tue, 13 Aug 2002 22:02:56 -0400
- Organization: [very little]
>
From: "Hamish Allan" <email@hidden>
>
To: <email@hidden>
>
Subject: Manipulating multiple files in arbitrary applications
>
Date: Tue, 13 Aug 2002 17:22:08 +0100
>
>
Hi,
>
>
I'm new to AppleScript (and Macs in general, for that matter) and I'm
>
wondering whether it's possible to use it to perform batch operations on
>
multiple files in arbitrary applications.
>
>
>From what I have managed to pick up on, there are some AppleScript
>
extensions which allow the user to perform point-and-click operations and
>
type on the keyboard. But I haven't found any example scripts doing anything
>
similar to what I am looking to do.
>
>
What I want to do is simple. For a collection of files (e.g., traverse a
>
folder and its subfolders), open them in the application, and simply save
>
them again (the purpose of this exercise is to ensure that their file
>
associations are correct - the files in question were created on a PC).
>
>
My pseudo-code would look something like this:
>
>
for filename in "folder" plus subfolders
>
tell application "myapp"
>
open filename
>
save as filename
>
end tell
>
end for
>
>
Could anyone tell me whether this is possible, and if so whether I need any
>
extensions, and where I might find some example code for doing this?
There's an easy way, using a scripting addition, which is by far the
fastest way. This takes either Jon's Commands or Akua Sweets. Akua
Sweets hasn't been updated for OS X. Jon's commands has but I have no
experience using it under that OS.
The relevant command in Akua Sweets is "the entries in". The one in
Jon's Commands is "walk folders".
There's the hard way, using a recursive handler, which takes
approximately 100 times as long to run:
set firstFldr to (choose folder)
procFldr(firstFldr)
on procFldr(theFldr)
tell application "Finder"
try
set fileList to (files of theFldr) as alias list
on error
set fileList to (files of theFldr) as alias as list
end try
end tell
repeat with aFile in fileList
tell application "someApp"
try
open aFile
close aFile
end try
end tell
end repeat
tell application "Finder"
try
set fldrList to (folders of theFldr) as alias list
on error
set fldrList to (folders of theFldr) as alias as list
end try
end tell
repeat with aFldr in fldrList
procFldr(aFldr) -- recursion occurs here
end repeat
end procFldr
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[8/13/02 10:01:43 PM]
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.