Re: Choose folder dialog and then process contents?
Re: Choose folder dialog and then process contents?
- Subject: Re: Choose folder dialog and then process contents?
- From: Graff <email@hidden>
- Date: Wed, 06 Oct 2004 15:46:07 -0400
Wow, 25 attachments. Is this a new record? Anyone know why
attachments still aren't being filtered from this list considering how
annoying they can be?
This message definitely goes straight to the trash for me. Garbage in,
garbage out.
- Ken
On Oct 6, 2004, at 3:34 PM, Aaron Rosenblum wrote:
I am curious how I might go about creating an applescript that allows
the user to use a file browser to select a folder, and then dives into
that folder processing the files and subfolders. I found this
excellent Subroutine in the "AppleScript: Essential Subroutines" page
in the Apple site:
http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.09.htm
This piece of code does exactly what I want, except it requires files
and folders to be dropped on it because it is a droplet. How might I
adapt this to make it so the user can set the folder to start with
instead of dropping it on the script?
FYI: I have tried adding:
set this_folder to (choose folder with prompt "Pick the folder
containing the files to process:") as string
tell application "System Events"
set these_items to every file of folder this_folder
end tell
But I get a: NSCannotCreateScriptCommandError when I try to run the
script. (When I added the above to the script, I removed the "on open
these_items" and "end open".
thanks
Aaron
-- the list of file types which will be processed
-- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
property type_list : {}
-- since file types are optional in Mac OS X, -- check the name
extension if there is no file type
-- NOTE: do not use periods (.) with the items in the name extensions
list
-- eg: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg",
".jpeg"}
property extension_list : {}
-- This droplet processes both files or folders of files dropped onto
the applet
on open these_items
<spacer.gif>repeat with i from 1 to the count of these_items
<spacer.gif>set this_item to (item i of these_items)
<spacer.gif>set the item_info to info for this_item
<spacer.gif>if folder of the item_info is true then
<spacer.gif>process_folder(this_item)
<spacer.gif>else if (alias of the item_info is false) and ¬
<spacer.gif>((the file type of the item_info is in the type_list) or ¬
<spacer.gif>the name extension of the item_info is in the
extension_list) then
<spacer.gif>process_item(this_item)
<spacer.gif>end if
<spacer.gif>end repeat
end open
-- this sub-routine processes folders
on process_folder(this_folder)
<spacer.gif>set these_items to list folder this_folder without
invisibles
<spacer.gif>repeat with i from 1 to the count of these_items
<spacer.gif>set this_item to alias ((this_folder as text) & (item i of
these_items))
<spacer.gif>set the item_info to info for this_item
<spacer.gif>if folder of the item_info is true then
<spacer.gif>process_folder(this_item)
<spacer.gif>else if (alias of the item_info is false) and ¬
<spacer.gif>((the file type of the item_info is in the type_list) or ¬
<spacer.gif>the name extension of the item_info is in the
extension_list) then
<spacer.gif>process_item(this_item)
<spacer.gif>end if
<spacer.gif>end repeat
end process_folder
-- this sub-routine processes files
on process_item(this_item)
<spacer.gif>-- NOTE that the variable this_item is a file reference in
alias format
<spacer.gif>-- FILE PROCESSING STATEMENTS GOES HERE
end process_item
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden