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

Choose folder dialog and then process contents?


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

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

GIF image

repeat with i from 1 to the count of these_items

GIF image

set this_item to (item i of these_items)

GIF image

set the item_info to info for this_item

GIF image

if folder of the item_info is true then

GIF image

process_folder(this_item)

GIF image

else if (alias of the item_info is false) and ¬

GIF image

((the file type of the item_info is in the type_list) or ¬

GIF image

the name extension of the item_info is in the extension_list) then

GIF image

process_item(this_item)

GIF image

end if

GIF image

end repeat
end open

-- this sub-routine processes folders
on process_folder(this_folder)

GIF image

set these_items to list folder this_folder without invisibles

GIF image

repeat with i from 1 to the count of these_items

GIF image

set this_item to alias ((this_folder as text) & (item i of these_items))

GIF image

set the item_info to info for this_item

GIF image

if folder of the item_info is true then

GIF image

process_folder(this_item)

GIF image

else if (alias of the item_info is false) and ¬

GIF image

((the file type of the item_info is in the type_list) or ¬

GIF image

the name extension of the item_info is in the extension_list) then

GIF image

process_item(this_item)

GIF image

end if

GIF image

end repeat
end process_folder

-- this sub-routine processes files
on process_item(this_item)

GIF image

-- NOTE that the variable this_item is a file reference in alias format

GIF image

-- 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: Choose folder dialog and then process contents?
      • From: Graff <email@hidden>
  • Prev by Date: Word length
  • Next by Date: Re: Word length
  • Previous by thread: RE: Word length
  • Next by thread: Re: Choose folder dialog and then process contents?
  • Index(es):
    • Date
    • Thread