finder - open selected file with specific application

Hey all,

I was wondering if someone could help out with this

Desire Functionality

  1. select a file
  2. open that selected file with specific application

code so far:

  • selects path shows the

	tell application "Finder"
		set filepath to selection as Unicode text --> The path to the one selected item.
	end tell

output: Macintosh HD:Users:…

  • open that selected file with specific application
    terminal: open -a “Application name” “File Path” -this works, it opens the selected file with the desired application

Issues:

  • filepath output is :----: but the terminal out is expected to be /—/—/
  • how do you “do shell scipt” and use the file path in the command?

Any help would be appreciated

Hi,

the Terminal is not needed


tell application "Finder"
	set sel to selection
	if sel is not {} then
		set filepath to item 1 of sel as text --> The path to the one selected item.
		open filepath using application file id "com.apple.TextEdit" -- bundle identifier of the designated application
	end if
end tell


Stefan as always thanks for the quick reply.

The script opens the selected file with the default application. However how would you specify another application to open the selected file?

Elegant solution but I wanted to for instance open a selected file (.mp3) in quicktime player but by default opens in itunes.

Hm,

when I use


.
open filepath using application file id "com.barebones.textwrangler" 
.

it opens every text file with TextWrangler even TextEdit is the default application

On my machine it does open with QuickTime Player with


open filepath using application file id "com.apple.QuickTimePlayerX"

great! i had the plist included…

it works exactly as desired.

thanks again, for the patience and clarification

Is it possible to tweak this and instead of an app use an executable that resides inside a bundle to open the currently selected file?

What I intend to do is to directly launch the calibre ebook-viewer executable for opening eg. epub files. I suppose this ebook-viewer is a POSIX executable and it can take a filename as an argument.

Thank you for your help.