Posted on 10-19-2014 09:58 PM
I am needing to deploy VLC to all machines, and I am wanting to make all the common video file formats default to open with VLC
I was expecting a .pkg installer when I downloaded it, but I got a straightforward .app and no run on first launch setup to capture with composer.
I captured changing the default file associated for a .mov file and I saw the information is kept in /Users/X/Library/Preferences/com.apple.LaunchServices.plist is editing this with all the required file types the best way to go about setting this up? Considering it would overwrite other settings I'm a bit unsure on that one.
Is there a better way to capture default programs?
Posted on 10-20-2014 05:06 AM
thats the file that handles the filetype to applications yes, but adding items to it like you want is a little tricky.
If you're happy to simply configure it the way you want with the keys in there that setup VLC for your file types and push it out you could do that via a composer dmg with FUT and FEU
But if you simply want to modify existing users copies with just the keys required for VLC then you might want to have a look at this thread which discusses doing exactly that, create a script and then deploy the script with a launchagent or set it to a once off login policy
duti looks promising
http://apple.stackexchange.com/questions/49532/change-the-default-application-for-a-file-extension-via-script-command-line
Posted on 10-20-2014 03:02 PM
@calumhunter Looks like duti will do exactly what I need, thanks!
Posted on 10-20-2014 08:34 PM
I've run in to a bit of a problem.
I have a policy that A, Installs the duti binary, B, adds VLC to /Applications/ and C, moves a .plist to /Library/Preferences/ and then runs a script to invoke duti to read the .plist which should then change the file associations.
Only it doesn't change them. I think it may be because it is running the command as root?
If I run the command manually on a test machine then it does change it.
I'm unsure how I can make the command run as the logged in user?
It doesn't require a sudo.
(unmarked answer as the problem isn't quite solved, will re-mark after solution.)
Posted on 10-21-2014 01:21 AM
you could have your login script call another script which does the the duti stuff, and have it call that script as the currently logged in user... bit ugly
better option might be to package a launch agent and script that does the duti stuff.. so your launchagent runs at load (login) fires off the script that does the duti work then deletes the launchagent and the script.
Posted on 10-21-2014 03:13 PM
It does all seem rather messy, I had been considering the first option, but I think using a Launch Agent would be much cleaner, I'll have to give that a shot.
Posted on 10-21-2014 04:51 PM
Can't quite seem to get my launchagent working! Argh!
Posted on 10-21-2014 04:59 PM
remove the <string> sh</string> you dont need it
remove the launchonlyonce, remove the plist with the script
make sure the script in /Library/Scripts/ is executable
your launchagent permissions should be 644
the script should be 755
Posted on 10-21-2014 05:40 PM
Thanks for the help @calumhunter
I've removed both the sh string and the LaunchOnlyOnce key, but I still seem to be seeing that error in logs!
Permission is 755 on the LaunchAgent.
Posted on 10-21-2014 06:17 PM
as above check the permissions 644 not 755
Posted on 10-21-2014 06:19 PM
also you have a typo
its
ProgramArguments
not
ProgramArguements
Posted on 11-16-2014 06:10 PM
I'm re-visiting this, I can't for the life of me seem to get it working.
I am trying to use duti still, but I am open to other options here.
I have my LaunchAgent running on startup, it's sitting in ~/Library/LaunchAgents/
If I try to use launchctl load ~/Library/LaunchAgents/agent.plist it returns "Operation already in progress"
When I try to run the script manually it completes and does what I want it to.
When I run plutil -lint ~/Library/LaunchAgents/agent.plist it returns OK
I'm really confused as to why it does not complete the actions in the script, no logs show in console for it at all.
Posted on 11-16-2014 07:17 PM
can you post the script and your launch agent.
also you should use reverse domain naming for your plist so something like:
au.com.compnow.mattsim.setopenwith.plist
Posted on 11-16-2014 07:35 PM
@Matt.Sim - you should consider getting a copy of LaunchControl and creating your Launchd file that way. I'm not saying it isn't possible to hand create one. If you consider it a challenge and a learning experience, then knock yourself out. But if you're more interested in just getting this done, let an application designed to create them the right way do it and save yourself the hassle.
Posted on 11-16-2014 08:33 PM
@mm2270 I'm looking at it now.. It doesn't really make it easier for me, if not more difficult.. I don't see any way in there to run a script?
The script is simply this: (I just want to get this working before I add anything else in.)
#!/bin/sh
/usr/local/bin/duti -s org.videolan.vlc .avi all
/usr/local/bin/duti -s org.videolan.vlc .mov all
The plist is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>duti.videolan.vlc</string>
<key>ProgramArguments</key>
<string>/Users/casper/Library/vlc.sh</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Posted on 11-16-2014 08:45 PM
Its the field called "Program to run" Basically corresponds to the ProgramArguments item in the plist. Just type in the path to the script file, like what you have above. Actually, all you really need to do is have your LaunchAgent installed on your Mac and open LaunchControl. It will see it in the jobs list (under User Agents) and actually tell you if something is wrong with it.
In looking at your posted launchd plist above, I'm curious, but is the path to that script inside an actual user directory? If so, are you logging in as that user "casper" when testing?
Posted on 11-16-2014 08:48 PM
@mm2270 I'll take another look at it soon then.
The path is inside the user directory yeah, no real reason for it being there, just where I put it for testing purposes, and yes, it's logged in as the user casper.
Posted on 11-16-2014 08:54 PM
is the script executable?
I would put the script somewhere like /Library/Scripts
it should have 755 permissions on it
I'm not 100% sure but does the label have to match the name of the plist? I just looked at a couple of mine and they match the file name minus the .plist extension
other than that it should work fine. Also what happens if you comment out
/usr/local/bin/duti -s org.videolan.vlc .avi all
/usr/local/bin/duti -s org.videolan.vlc .mov all
and instead put in somehting like this
touch ~/Desktop/This_Is_a_test
then log in and try again that should just create an empty file on the desktop that way you know that the launch agent is firing off your script.
Posted on 11-16-2014 08:55 PM
again just double check the permissions 644 for the launchagent and 755 for the script
Posted on 11-16-2014 09:35 PM
It seems that the issue may have been the ProgramArguments string, LaunchControl created it with Program and it seems to work (otherwise it created it exactly the same).
I've set the plist to 664 and the script to 775 and moved the script to /Library/Scripts/, which is where I had it initially.
Tested it on one of my test machines and it seems to be working as intended now.
Posted on 11-16-2014 10:23 PM
Give http://duti.org a go.
This is exactly what it's been written for.
Posted on 11-17-2014 02:31 PM
I'm with ben, use duti. in fact, I'd almost say if you're not using duti for this you're doing it wrong! lol.
Posted on 11-17-2014 02:32 PM
@bentoms @nkalister If you look above duti is exactly what I have been using.
Posted on 01-04-2015 03:57 AM
@Matt.Sim, you aren't setting the launch services plist via another method? Like a profile or something?
Posted on 01-04-2015 01:42 PM
@bentoms I used the LaunchA to run a script, I had just not written the LaunchA correctly, IIRC. Got this working in November.