theFile, this_File? Help needed!

Hello,
I’m new here and I’m hoping somebody can help me to get a small Applescript working the way I want it to…

The first thing to say is that I haven’t done any scripting in ages so I’m kind of pleased where I’ve got to. But then again try as I might I can’t make it do what I really want it to do. Here’s the story.

What I wanted was a script that, applied to any selected desktop file, imported the chosen file into Yojimbo, setting a flag on import and sending the original desktop file to the trash. And up to a point that’s what I’ve achieved…

set theFile to choose file

	tell application "Yojimbo"
	
		set newItem to (import theFile)
	
		set flagged of newItem to true
	
	end tell

	tell application "Finder" to move theFile to the trash

The Yojimbo side is working fine but the problem is the initial and unnecessary “choose file” instruction which opens a finder window for me to select the (already selected) file.

I’m wondering if something like

set this_file to theFile

is what I’m looking for… However, whatever it is I need, I can’t fathom the syntax and help is needed!

The final idea is either to make this script available via the menu bar or to put it through Automator, but the ultimate ideal is to reduce the keystrokes to a minimum.

Any help would be most welcome.

Hello.

What you want to do is to make Finder return its selection, preferably as an aiias list, then you can make Yojimbo import several files at once.

Hopefully this works, I don’t have Yojimbo, so I wouldn’t know…

tell application "Finder"
	set selFiles to selection as alias list
	if selFiles = {} then
		activate
		display dialog "No items were selected..."
		error number -128
	else
		repeat with aFile in selFiles
			tell application "Yojimbo"
				
				set newItem to (import aFile)
				
				set flagged of newItem to true
				
			end tell
			move aFile to the trash
		end repeat
	end if
end tell

Thanks for that, much appreciated…