applescript in Automator; how the delete .NEF files

Hello,

found on the Applescript forum the following script’

tell application "Finder" 
	delete (every file of (choose folder) whose name contains ".-")
	empty trash -- comment out to be sure not to delete wrong files
end tell

That works very well. But need to change it so I can use it in a automator workflow. So that it looks in the current folder (and not asking to choose a folder) from the workflow and deletes all files with the extension .NEF.
So did the folowing…but this doesn’t work I have no clue why

on run {input, parameters}
	
	tell application "Finder"
		delete (every file whose name ends with ".NEF")
		empty trash -- comment out to be sure not to delete wrong files 
	end tell
	
	return input
end run

Anyone knows whats wrong?

Thanks and have a nice weekend

Bob

ps know there are some actions in automator that can do the same but for some reasons those do not work for me

I think you want "whose name extension is “NEF”.

on run {input, parameters}
	tell application "Finder"
		delete (every file whose name extension is "NEF")
		--empty trash -- comment out to be sure not to delete wrong files 
	end tell
	return input
end run

Thanks Adam, but it didn’t work. Nothing happens.

strange thing is that following script does it great (as mentioned above)

tell application "Finder"
	delete (every file of (choose folder) whose name contains ".NEF")
	empty trash -- comment out to be sure not to delete wrong files 
end tell

mmmmmm… is it possible that I change that script in something like - know it doesn’t work but think you know what I mean;

tell application "Finder"
	delete (every file of (CURRENT folder) whose name contains ".NEF")
	empty trash -- comment out to be sure not to delete wrong files 
end tell

so that not have to choose in the workflow but that it look in the current folder automaticly

thanks

That’s what’s missing - the “of folder” bit. The folder the file is in has to be identified.

This works for me:

set p to (choose folder) as alias
tell application "Finder"
	delete (every file of folder p whose name extension is "JPEG")
end tell

I’m not an Automator user, but I assume that in your case, the “input” is an alias to a folder. Then every file of folder input whose …

Creating a workflow that deletes specific files from a folder passed from a previous action is pretty straighforward, here’s the list of actions in the workflow:

action 1 – some action that passes a folder references such as: Ask for Finder Items OR ignore this step and save the workflow as a Finder plugin then select a folder from the desktop and run the workflow. A reference to the selected folder will automatically be passed to the first action in the workflow

action 2 - Get Folder Contents

action 3 - Filter Finder Items

action 4 - Move to Trash

BTW, if you write script using the Run AppleScript action, rember that the items from the previous action are passed in the input variable:

on run {input, paramters}
	tell application "Finder"
		delete every document file of input whose name extension is "NET"
	end tell
end run

Note that “input” may be a list.

Hello thanks all for taking time to respond. Still have some problems but have pepared some examples to show you what’s happening;

The files can be downloaded through the following link

http://homepage.mac.com/snotolf/media/macscripter.zip

  1. You have folder that’s containing an original .NEF file
  2. A folder with some actions you w’ll probably need
  3. 4 workflows

Workflow A:

This workflow works. You can test it on the original folder. The .NEF file will be deleted. But you have the .zip file so you can grap a new .NEF file for the other worklfows.

Workflow B:

Put workflow A in a excisting workflow (work in progress) and the strange thing is that now it doesn’t work anymore. So had to implement the option that it asks for the user to select again a folder but that last step I do not want…

Workflow C:

Did a applescript in this workflow…and does not work, and have no clue why

Workflow D:

This contains a applescript and works fantastic but again it asks for a folder and I do not want that.

So guess you see what I want to do.

Thanks (again)

Bob

Merci Boucoup *) Jacques that worked fantasic!

Thanks :slight_smile:

*) pressume you’re from France

Bob