iPhone and Linux

Tuesday, October 27, 2009

Run a script from a Prowl notification

Prowl allows it's notifications to be opened in any app using Apple's custom url scheme. Here's how you can have a Prowl notification run a shell script.

What you need on your phone:
It has to be Jailbroken
Prowl
any BASH shell script that you want to run
curl on the phone: optional - only needed if you want output from the script sent through Prowl.

You're not going to be editing any system files or doing anything dangerous.

First, use my last post to create a fake app which will allow you to run your script by tapping an icon on SpringBoard.

Now, for my example, I will name my script "Test" (not Test.sh. It runs fine without the file extension and I'm not sure it would work later on if it has an extension)

Open your script's Info.plist and right above the "dict" closing tag, add these lines:

<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Test URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>rss</string>
</array>
</dict>
</array>


So your finished plist should look like this:

<?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>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>Test.sh</string>
<key>CFBundleIdentifier</key>
<string>com.myname.Test</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Test</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Test URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>rss</string>
</array>
</dict>
</array>
</dict>
</plist>
Edit "Test URL" and "rss." Change "Test" to the name of your script and rss to any app in Prowl's Redirections.plist.

Open Prowl's Redirections.plist and find rss, or whatever app you are using, and edit the lines below Key and URL to the name of your script:
   <key>Key</key>
<string>Test</string>
<key>URL</key>
<string>Test://</string>
Open Prowl and create a custom redirection by putting in an application name and selecting rss. I'll use "shoe" as an example application name

Using curl on my computer
curl -k https://prowl.weks.net/publicapi/add -F apikey=XXXX -F application="shoe" -F description="click view to run the Test script"

Send that notification with curl, click "view" when it pops up and it will run your script. Of course, there is no output unless you have a method of sending output in the script. Putting this in the script would send you another Prowl notification that the script was ran: curl -k https://prowl.weks.net/publicapi/add -F apikey=XXXX -F application="Test" -F description="the Test script was ran" Or put the output of the script into a variable and use description="$variable"

So what are the uses? Heck if I know. Maybe endless, maybe useless.

Blog Archive