• 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
2nd try: Choose folder dialog and then process contents?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

2nd try: Choose folder dialog and then process contents?


  • Subject: 2nd try: Choose folder dialog and then process contents?
  • From: Aaron Rosenblum <email@hidden>
  • Date: Wed, 6 Oct 2004 15:57:09 -0400

Hi,

It seems when pasting from script editor to Mail.app, it created a lot of spacer gif attachments that got included with my last message. Sorry about that. Here is the question that should not include those weird things.

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
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items)
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and ¬
((the file type of the item_info is in the type_list) or ¬
the name extension of the item_info is in the extension_list) then
process_item(this_item)
end if
end repeat
end open


-- this sub-routine processes folders
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) and ¬
((the file type of the item_info is in the type_list) or ¬
the name extension of the item_info is in the extension_list) then
process_item(this_item)
end if
end repeat
end process_folder

-- this sub-routine processes files
on process_item(this_item)
-- NOTE that the variable this_item is a file reference in alias format
-- 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
  • Follow-Ups:
    • Re: 2nd try: Choose folder dialog and then process contents?
      • From: Mr Tea <email@hidden>
    • Re: Choose folder dialog and then process contents?
      • From: Gnarlodious <email@hidden>
    • Re: 2nd try: Choose folder dialog and then process contents?
      • From: Graff <email@hidden>
  • Prev by Date: Re: Choose folder dialog and then process contents?
  • Next by Date: Re: Variable Ponderance
  • Previous by thread: Re: Choose folder dialog and then process contents?
  • Next by thread: Re: 2nd try: Choose folder dialog and then process contents?
  • Index(es):
    • Date
    • Thread