Sunday, November 14, 2010

Using BossPrefs

BossPrefs is a flexible toggle tool that lets you toggle any preference that you can toggle using a term program. It has a very powerful plug-in interface that lets you create a plug-in to handle any toggle. It should be the fastest loading services type app out because it grabs status asynchronously while the app is initializing rather than waiting on status from each plug-in before displaying the app window.
It also has the ability to add icons to its internal dock (that scrolls) to allow you to move all your settings types apps into one place. As of 1.56, BossPrefs does not auto hide icons so use Poof / Customize to hide the icons you add to the dock.

BossPrefs toggles come in one of two ways. Either the toggle is built into the app (edge, Bluetooth, wifi etc) or it is provided by an external plug-in. BossPrefs has a configuration screen that lets you toggle whether or not to display any of the built in toggles. But the plug-ins cannot be taken off the toggle screen. To remove the plug-in toggles, uninstall them.

Adding new toggles is not that difficult. But you must first know how to enable/disable the item you want to toggle in the term window. BossPrefs provides a GUI interface to allow you to add new toggles via the GUI Window. Basic toggle additions can be done via the GUI, but more complicated ones will require scripts to be written. First, let’s create a simple toggle via the GUI to restart springboard.
Load the configuration screen, select add, and you are presented with this screen:

Now we will type in the settings. In this case, I will call it “Respring”. The only command I need is to kill the springboard using “killall SpringBoard”. Killall is a BSD command in /usr/bin. I do not need a stop command since I’m not really starting a service. And I don’t need a command to detect if the process is running because springboard is always running. Therefore, I’ll put “asdf” or some garbage in those lines. I’ll leave the icon blank since I don’t have one. Here is my finished ReSpring screen:

And when I click save, I now have “ReSpring” added to my list of toggles:

When I toggle this, springboard resets. It works!
Now lets take a look at making a more complicated plug-in. For this, we will need to SSH into the iPhone. Take a look in /Applications/ dir. You see two dirs there: services and scripts. Services is the directory where you put new toggles. This is done by making a new text file. The name of the text file is the name of the toggle. For this example, let’s install the BossPrefs capture control within installer. So, go do that then return to this tutorial.
Now, inside the services directory, you should see a file called “Capture”. Lets open that file. You will see the following:

/bin/launchctl load -w /Library/LaunchDaemons/com.digitalagua.capture.plist
/bin/launchctl unload -w /Library/LaunchDaemons/com.digitalagua.capture.plist
These are 4 lines of text that correspond with the 4 entries in the GUI in order.
The first line is the command to type to start the toggle. This can be a single command issued or a bash script that you write for a more complicated start/stop. If you write a bash script, you can put this script into the scripts folder.
The second line is the command to type to stop the toggle. Just like above, this can be one command or a series of commands in a bash script.
The third line is how to determine whether or not the toggle is on or off for state. This is the trickiest line. There are three possibilities for this line.
  • Plist Identifier - If it is a plist identifier format (example: com.digitalagua.capture.plist), it will be piped to launchctl list.
  • Exist - If line 3 starts with the word “exist”, then it will use existence of a file on disk as the “ON” state, and if the file does not exist, the plug-in is “OFF”. This is how the safari download plug-in works.
  • Process - If neither of the above is the case, the string in line 3 is piped to ps -au command and looked for in a grep of such command. This is how you can determine if a binary is running on the system.
  • cmd - As of BossPrefs 1.57 and newer, you can use a script of your choosing to determine if the toggle is running or not. Just put “cmd yourscript params” where yourscript and params is the path and filename of your script and params are the parameters to pass. For example, I modified Capture plug-in to use this: “cmd ps au | grep ScreenGrab >> /dev/null”. If the script returns 0, the toggle is considered running. If it returns anything else, it is considered not running.
The 4th line is the optional path to the icon to display. The icon should be a 20 x 20 png file.
For the next example, lets take a look at the safari download plug-in. This is a bit tricky. The plug-in is enabled (ON) when some files are copied into place and is disabled (OFF) when those files are deleted. The toggle just moves those files to another folder to disable the plug-in and moves them back to enable it. Here is the SafariDL file from the services folder:

exist /System/Library/Internet Plug-Ins/File Download Plugin.webplugin/LCDownloader
Notice that the first two lines are scripts. This is the contents of the script:
cp -r /var/mobile/Library/BossPrefs/webplugin /System/Library/Internet\ Plug-Ins/File\ Download\ Plugin.webplugin
rm -rf /var/mobile/Library/BossPrefs/webplugin
cp /var/mobile/Library/BossPrefs/enabled.plist /System/Library/Internet\ Plug-Ins/QuickTime\ Plugin.webplugin/enabled.plist
rm -f /var/mobile/Library/BossPrefs/enabled.plist
cp /var/mobile/Library/BossPrefs/disabled.plist /System/Library/Internet\ Plug-Ins/QuickTime\ Plugin.webplugin/disabled.plist
rm -f /var/mobile/Library/BossPrefs/disabled.plist
/usr/bin/killall MobileSafari
Also, we are using the existence of LCDownloader to determine if the plug-in is enabled or disabled.
On 1.1.3/4 the troubleshooting is especially tricky because the plug-in actually runs as user mobile. You may need to add the +s attribute and set the owner to root to the start/stop type scripts in the scripts folder to allow it to run with root permissions.
You can test your scripts in SSH but make sure you run them as user mobile.


Post a Comment

Related Posts Plugin for WordPress, Blogger...
Twitter Delicious Facebook Digg Stumbleupon Favorites More