osx - Locating and modifying Services in OS X
2014-07
So, I'd like to be able to add a website viewed in Firefox to the Reading List feature in iOS so I can check stuff on my iPhone. I was inspired by https://apple.stackexchange.com/questions/51534/reading-list-in-other-browsers but executing a shell script from within a Firefox Addon written in javascript isn't possible (but that's probably a good thing anyway). However, there is a Service that can add an URL to the reading list. It looks like this:
The service works (obviously), but it opens up Safari, which isn't really something I need.
So in short, I'd like to locate modify the Service so it closes Safari after the URL has been added to the reading list. I tried recreate the Service in Automator, but couldn't find the "add URL to reading list" anywhere.
I've already checked ~/Library/services and /System/Services, no sign of that specific service.
I'm trying to run an alternate install of apache httpd (don't ask) on my Mac. I can do it but it only runs as long as I'm logged in, and I keep having to type
sudo /opt/local/apache2/bin/apachectl -k start
and was wondering if there was a way to setup a service on my Mac so I don't have to keep doing this.
The best option is to use launchd
the built in replacement for cron
, init
and xinetd
. To do so you need to create an XML document (specifically a .plist) to define what you want to do. A program called Lingon provides an excellent GUI for doing this and the installation as well.
You can save the following file as com.example.apache2.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<true/>
<key>Label</key>
<string>com.example.apache2</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/opt/local/bin/apache2/bin/apachectl</string>
<string>-k</string>
<string>start</string>
</array>
</dict>
</plist>
You then want to install this .plist within /Library/LaunchDaemons
because you want this to run when the computer starts up (as a service). You can do this by copying the file to /Library/LaunchDaemons
(User Daemons in Lingon) and running the command sudo launchctl load -w /Library/LauchDaemons/com.example.apache2.plist
. Then whenever the computer is started up, the command is run. Of note, Launch Daemons in /Library
are run as root so you don't need the sudo.
For more information on launchd, check out the man page, the man page for launchd.plist, Getting Started with launchd, or you can search here on Super User as there are several questions already about launchd.
The correct way to do this would be through launchd.