Hello. I’ve created this mplayer droplet based on a script that was in the forums:
--code borrowed from http://bbs.applescript.net/viewtopic.php?id=4547
on open someFiles
repeat with i in someFiles
my_mplayer(i)
end repeat
end open
to my_mplayer(i)
do shell script "/usr/local/bin/mplayer " & quoted form of POSIX path of i
end my_mplayer
It does what I want (opens media files with mplayer) and I’m mostly happy with it. Still, there are some improvements that I would like to add:
- is there any way to hide the binary icon, so that only the Script icon appears;
- restrict the type of files that can be dropped (.avi, .mpg, etc);
- associate the aforementioned file types to this droplet.
Basically this droplet would be some sort of wrapper to the binary.
Hi Kaonashi,
you can restrict the file types e.g. by filtering the name extension,
if you like, add further items to the property line
property fileTypeList : {"avi", "mpg"}
on open someFiles
repeat with i in someFiles
if name extension of (info of i) is in fileTypeList then my_mplayer(i)
end repeat
end open
to my_mplayer(i)
do shell script "/usr/local/bin/mplayer " & quoted form of POSIX path of i
end my_mplayer
Thanks. It now filters based on file type. 
Another thing that I would like to add to this droplet is a choice of different mplayer configurations. I have mplayer and two aliases: mplayer_slow and mplayer_subs.
Is it possible to, after dragging the file, open a window with three buttons which allow the user to choose which mplayer does he want and load the choice?
This would be a small window with just three buttons (mplayer, mplayer_slow and mplayer_subs) and an exit if the user pressed the ESC key. Is this possible in AppleScript?
well the syntax would be like this
display dialog "" buttons {"mplayer", "mplayer_slow", "mplayer_subs"} with title "Select a player"
The problem is applescript only allows 3 buttons so you can’t put in an exit button in the above scenario and hitting escape does nothing… no way to my knowledge to have escape cancel out a dialog window without moving into xcode.
::edit::
You could do this though 
choose from list {"mplayer", "mplayer_slow", "mplayer_subs"} with title "Select a player"
Thanks for your help.
How will I incorporate the list in the aforementioned code, linking each choice to the shell script that I want to run?
Hi,
assuming that the names of the different players are exactly the argument for the shell script,
try this:
property fileTypeList : {"avi", "mpg"}
on open someFiles
set player to choose from list {"mplayer", "mplayer_slow", "mplayer_subs"} with prompt "Select a player"
if player is false then return
set player to item 1 of player
repeat with i in someFiles
if name extension of (info for i) is in fileTypeList then my_mplayer(player, i)
end repeat
end open
to my_mplayer(p, i)
do shell script "/usr/local/bin/" & p & space & quoted form of POSIX path of i
end my_mplayer
Actually they’re not different players. I’m using aliases to different sets of options. Why can’t AppleScript execute the mplayer command and the bash aliases without giving it the full path?
Because for a number of reasons AppleScript uses the SH shell. So paths/alias’ in your personal shell may be different. You can specify the shell though of your choice, but most would say it’s just a better idea to specify full paths… and I agree.
For more info see Tech Note: TN2065 - http://developer.apple.com/technotes/tn2002/tn2065.html
While playing with the mplayer configuration file, I managed to get the options I want to only one command. The final touches on the droplet are these:
- the mplayer command line is: mplayer -vf expand=0:-20:0:0,eq2=1.2 -subfont-text-scale 6, which is inside the list. How do I associate this with the item on the list so that it doesn’t appear this huge command?
- is it possible to make one of the list items the default?
Once again, thank you for all your help.
Hi Kaonashi,
the following script doesn’t work probably, because I don’t know the exact syntax of the mplayer command
but you can see the principle
property fileTypeList : {"avi", "mpg"}
property playerList : {"mplayer", "mplayer_slow", "mplayer_subs"}
property cmdList : {"mplayer -vf expand=0:-20:0:0,eq2=1.2 -subfont-text-scale 6", "--cmd2--", "--cmd3--"}
on open someFiles
set player to choose from list playerList with prompt "Select a player" default items {item 1 of playerList}
if player is false then return
set player to item 1 of player
repeat with x from 1 to count playerList
if player is item x of playerList then
set cmd to item x of cmdList
exit repeat
end if
end repeat
repeat with i in someFiles
if name extension of (info for i) is in fileTypeList then my_mplayer(cmd, i)
end repeat
end open
to my_mplayer(cmd, i)
do shell script "/usr/local/bin/" & cmd & space & quoted form of POSIX path of i
end my_mplayer
That’s perfect. I’ve managed to associate all files with this script but how can I define a personalized icon for the filetypes that it handles?