Using Prowl notification to run a script on your phone

An iPhone client for Growl available on the App Store.

Using Prowl notification to run a script on your phone

Postby fubaya » Mon Oct 26, 2009 10:12 pm

This is officially nerdy. I'm not sure I will even have a use for it, but it's cool enough I had to try it. I have several BASH shell scripts which I run from an icon on SpringBoard (I'll show you how) and after reading cjduckk's post about editing the GV Mobile and Prowl plist files to launch GV with a custom url, I wondered if I could use the same method to launch a script on my phone from a Prowl notification. To my surprise, it actually works.

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 you have to take your script and make a fake app out of it so it can be ran from SpringBoard. If you don't want it on SpringBoard, you may be able to delete the icon.png or hide it some other way, but I assume these steps are necessary to make the iPhone see your script as an app.

Note: your script shouldn't need to run for long because it will open a full screen png "splash screen" which renders your phone blank until the script exits. You can kill the script by pushing the home button at any time.

In this 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)

Make a folder called Test.app in /Applications. In that folder put:
Your bash shell script
An icon named icon.png
A plist file
A 320x460 background image named Default.png
A file named PkgInfo - the only contents are: APPL????

I'm not certain you need those last two but it took me forever to get this working right and those two were copied from another app and it works so I still use them when I create fake apps.

Open the Info.plist and edit the three things between the string tags under these keys:
CFBundleExecutable - Change this to the name of your script
CFBundleIdentifier - this can be anything but it must be unique for every script/app and in the "reverse dns" from of: com.myname.test or net.ThisIsA.Script
CFBundleName - Make this the name you want to appear under the icon on Springboard
Code: Select all
<?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</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>
</dict>
</plist>


Restart Springboard and with any luck you will have a new icon which will run your script when tapped. You can even use curl in the script to send the output to Prowl and get a notification with whatever output comes from the script. It's a strange way of doing things, running a script, having the output go out over the cell network, through the internet and back to your phone, but hey, it works and it's often faster than using MobileTerminal.

Now, open your script's Info.plist and right above the "dict" closing tag, add these lines:
Code: Select all
        <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:
Code: Select all
<?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

Code: Select all
<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.
fubaya
Harmless
 
Posts: 20
Joined: Fri Sep 04, 2009 10:15 pm

Re: Using Prowl notification to run a script on your phone

Postby fubaya » Tue Oct 27, 2009 7:18 pm

I did find a use for this trick. I use the Vuze (formerly Azereus) torrent client. It has a plugin for controlling it through the web and another plugin (iZureus) to format the control page for the iPhone. You could bookmark http://YOUR-IP:6886 in Safari but I try not to have to remember my home IP address and never "hardcode" it into a script or bookmark in case it changes a month later or something. So I have a cron that watches for an IP change and Prowls me the new IP which I put in a text file named homeip and read from that if needed. E.g. instead of "ssh me@123.45.67.890" I use "ssh me@$(cat homeip)" and never need to type or remember the actual IP.

I have one of those fake apps named "Vuze" with a nice Vuze icon. When I click it, it grabs my home ip address and automatically logs me into the Vuze control page in Safari using openURL from Erica Utilities (in Cydia).

#! /bin/sh
ip=$(cat /var/mobile/homeip)
openURL http://user:pass@$ip:6886

I have a cronjob at home which checks my finished torrent directory and Prowls me if anything is new. By adding this to Prowl and adding a redirection, I can have Prowl redirect to my Vuze script which opens the Vuze control page.
Code: Select all
<dict>
<key>Display</key>
<string>Vuze</string>
<key>Key</key>
<string>vuze</string>
<key>URL</key>
<string>vuze://</string>
</dict>


So anyway, for a non-developer, it's kind of cool to have 2 lines of script which behave as an app and can be ran through a Prowl redirection, and it's nice to be able to open and control Vuze remotely after a notification tells me that a torrent is finished. Other than that, the market for this trick is probably about 3 people in the world. I hope to play around with it to see if I can get the text from a notification into a script, which would be very useful. Not sure if it is possible though.
fubaya
Harmless
 
Posts: 20
Joined: Fri Sep 04, 2009 10:15 pm


Return to Prowl

Who is online

Users browsing this forum: No registered users