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

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


  • Subject: Re: 2nd try: Choose folder dialog and then process contents?
  • From: Graff <email@hidden>
  • Date: Wed, 06 Oct 2004 16:28:12 -0400

Just have the user choose a folder and then pass that folder to the "process_folder" handler. If you put that into a "on run" handler then the script will act the way that you are asking. You can remove the "on open" handler if you no longer need it.

Here's the modified script:

----
-- 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 : {}


-- added this handler to take care of directly running the script
on run
  set theFolder to choose folder
  process_folder(theFolder)
end run

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


- Ken

On Oct 6, 2004, at 3:57 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".

_______________________________________________ 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
References: 
 >2nd try: Choose folder dialog and then process contents? (From: Aaron Rosenblum <email@hidden>)

  • Prev by Date: RE: Word length
  • Next by Date: Re: Choose folder dialog and then process contents?
  • Previous by thread: 2nd try: Choose folder dialog and then process contents?
  • Next by thread: Re: Choose folder dialog and then process contents?
  • Index(es):
    • Date
    • Thread