opening file using variable

Hi,

I’m having trouble (yes, I’m a novice indeed!) opening files using the “open” applescript command. To be a little more specific: what I want to do is to tell MPlayer to open a movie of my choice. Now, if I tell Mplayer to “open [“file.avi”]” it opens the file using the default application that the file is set to open with (Quicktime, for example), instead of MPlayer. Changing the line to "open alias [“file.avi”] works fine, the file is opened in MPlayer just like I want it to, but when I’m using a variable (which is what I want to do) instead of typing the filename manually, I get the following applescript error:

“Can’t make «class docf» “MOVIE.AVI” of «class cfol» “MOVIE_FOLDER” of «class cfol» “SUB_FOLDER” of «class cfol» “Users” of «class sdsk» of application “Finder” into the expected type.”

I’ve tried telling Finder to “open the_selection using MPlayer” as well, but it doesn’t work either. Below is a simplified (and rather pointless) version of the script. Any kind of help is really appreciated.

Thanks!
Arnold

property movie_folder : alias “HD:Movies:”

tell application “Finder”
set movie_library to choose folder with prompt “Choose a folder:”
set current_folder to movie_library
set folder_name to name of current_folder
set file_list to name of every item of current_folder
set folder_list to {current_folder}
set the_selection to item 1 of current_folder
end tell

tell application “MPlayer OS X 2”
open alias the_selection
end tell

Does it work if you change this: open alias the_selection

To this: open alias (the_selection as text)

:?:

– Rob

No, not really. That opens MPlayer, but returns the following error (just as it does if I tell Finder to “open the_selection using MPlayer”, except that it in that case the file opens with its default app): “MPlayer OS X 2 got an error: alias “HD:Movies:Movie.avi” doesn’t understand the open message.”

As far as I know MPlayer is not scriptable, the version (2.0b4) I have does not have a scripting library. You might have better luck with VLC, which is scriptable and free…

http://www.videolan.org/vlc/download-macosx.html

Good luck…

This might work even if it isn’t scriptable. It should behave as if a file was dropped onto MPlayer’s application icon.

tell application "Finder" to open alias (the_selection as text) using "path:to:MPlayer application"

– Rob

Rob, that does work. Thanks

set the_selection to choose file
tell application "Finder" to open alias (the_selection as text) using "Applications:MPlayer OS X"

Thanks Rob, thanks Greg!

Works like a charm now. Oh, and by the way, VLC is not scriptable either, at least not yet, altough I’ve heard that it’s going to be in future versions.

Thanks again!
A.

Hi Arnold, I think VLC started adding AppleScript support in versin 0.5.2. Anyhow the current version 0.6.0 has a Scripting Library that looks pretty solid. Drag and drop VLC’s icon onto the Script Editor’s icon to open it. I haven’t tried scripting the app myself, but since it has a library it should be scriptable.