a noobie query

I’m only just beginning with Applescript and need to run scripts to move files about and/or run them.

The following script is to get files out of folders within a folder and then open them

tell application "Finder"
	set theFolder to folder choose folder with prompt "Choose the folder"
	set filelist to every file of every folder of theFolder -- whose name ends with "session"
	repeat until filelist is {}
		set theFile to (first item of filelist)
		set filelist to rest of filelist
		open theFile --with {/Applications/Capture One PRO 3.7/Capture One PRO}
	end repeat
end tell

the ‘whose name ends with’ section is commented out because it won’t work - don’t know why - all the files have ‘.session’ on the end

filelist contains the files I want, but apparently not in the form the command ‘open’ wants

the commented out ‘with’ section won’t compile

Welcome. :slight_smile:

Try something like this:

choose folder with prompt "Choose the folder"

tell application "Finder"
	set fileList to (every file of every folder of result whose name extension is "session") as alias list
	
	repeat with thisItem in fileList
		open thisItem
	end repeat
end tell

Thanks, but on running it I get (from event window):

tell current application
choose folder with prompt “Choose the folder”
alias “WD400:1091DA:”
end tell
tell application “Finder”
get every file of every folder of alias “WD400:1091DA:” whose name extension = “session”
“Finder got an error: Unknown object type.”

Which version of Mac OS X are you on?

OS X 10.4.11, Mac Pro (2x 3Ghz)

Hi, natcarish

The Finder reference every file of every folder of theFolder whose name ends with “session” means “every file in ((every folder whose name ends with “session”) in theFolder)”. There’s no direct way in the Finder to get “every file whose name ends with “session” in every folder of theFolder”. You either have to cycle through the folders or you might be able to use entire contents:

tell application "Finder"
	set fileList to every file of entire contents of theFolder whose name ends with "session"
end tell

This returns the files you want, but also any matching files in theFolder itself or in any subfolders of its folders.

‘with’ should be ‘using’. POSIX paths should be in quotes, not braces. I’m not sure if the Finder understands POSIX paths anyway. The application file name given in your path doesn’t have a name extension and so probably won’t be found.

The simplest approach overall would probably be to cycle through the theFolder’s subfolders:

tell application "Finder"
	set theFolder to folder (choose folder with prompt "Choose the folder")
	set subfolders to every folder of theFolder
	repeat with thisSubfolder in subfolders
		open (get every file of thisSubfolder whose name ends with "session") using file "Applications:Capture One PRO 3.7:Capture One PRO.app" of startup disk
	end repeat
end tell

I dropped the whose filter when I was testing. Oops!

Thanks a lot, that sorted it