Skip to content

Instantly share code, notes, and snippets.

@goodevilgenius
Last active October 26, 2017 14:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save goodevilgenius/e705c70a460277eee122 to your computer and use it in GitHub Desktop.
[Android Tasker Wallpaper Mirror] These can be used to get your desktop backgrounds on your Android device #RSS #Android #Tasker

Tasker Desktop Mirror

N.B. Python for Android (required for this) doesn't work on Android 5.0. I suspect this is due to an incompatibility with the ART runtime. Additionally, it seems there's been little to no development on Python 4 Android for quite a while. It appears to be a dead project. So, if you are running a recent version of Android, this won't work for you. I'm considering alternatives, as I was using quite a few Python-based Tasker tasks.

These scripts allow a person using the Variety desktop switcher to copy their backgrounds to their Android device automatically through Tasker and regularly switch backgrounds.

Firstly, a publicly accessible web server is required. You'll have to add the make_image_rss.sh to your variety set_wallpaper script. The script is normally found (on Linux) at ~/.config/variety/scripts/set_wallpaper. Simply add the following line to the end of the file:

bash /path/to/make_image_rss.sh "$3" /path/to/wallpaper http://example.com/wallpaper

In this line, make sure to use the right /path/to/make_image_rss.sh. /path/to/wallpaper should be the path on your filesystem to the folder where your web-accessible images will be stored. http://example.com/wallpaper will be the same path on the web.

Next, on your Android device, you will need Tasker, SL4A, and Python for Android.

You will need download_rss.py on your Android device. Don't bother trying to run it straight from SL4A. It won't work without Tasker.

Within Tasker, you'll need a few variables set:

  • %WALLPAPERFEED should be the full path to your feed. In the example above, it would be http://example.com/wallpaper/feed.xml
  • %WALLPAPERDIR will need to be the path on your device where you want to store your images. I have mine set to /storage/sdcard0/Wallpapers. It will, of course, need to be a path that's writable by SL4A.

Next, you'll need the Download From RSS task, the Random Wallpaper task, and the wallpaper_switch.js script. Put the script in your Tasker/scripts/ folder (or modify the task to point to the path you use). Then import both tasks.

Finally, you'll need some profiles to run those tasks. I have Random Wallpaper Switch run every twenty minutes, and Download From Rss run every hour.

<TaskerData sr="" dvi="1" tv="4.4u1m">
<Task sr="task13">
<cdate>1405889980896</cdate>
<edate>1405955953195</edate>
<id>13</id>
<nme>Download From Rss</nme>
<pri>10</pri>
<Action sr="act0" ve="6">
<code>112</code>
<Str sr="arg0" ve="3">download_rss.py</Str>
<Int sr="arg1" val="0"/>
<Str sr="arg2" ve="3">%WALLPAPERDIR,%WALLPAPERFEED</Str>
</Action>
<Img sr="icn" ve="2">
<nme>hl_content_attachment</nme>
</Img>
</Task>
</TaskerData>
#!/usr/bin/python
import xml.etree.ElementTree as ET
import urllib
import sys
import os.path
import android
droid = android.Android()
if (len(sys.argv) > 1):
u = sys.argv[1]
else:
try:
u = droid.getIntent().result[u'extras'][u'%WALLPAPERFEED']
except:
u = None
if (len(sys.argv) > 2):
p = sys.argv[2]
else:
try:
p = droid.getIntent().result[u'extras'][u'%WALLPAPERDIR']
except:
p = None
if u is None or p is None: sys.exit(1)
r = urllib.urlopen(u)
x = ET.parse(r)
item = x.getroot()[0].find('item')
link = item.find('link').text
save_path = os.path.join(p,os.path.basename(link))
if not os.path.exists(save_path):
urllib.urlretrieve(link, save_path)
droid.makeToast('Saved ' + link + ' to ' + save_path)
#!/bin/bash
# $1 is the path to the image
# $2 is the path to the folder
# $3 is the URL to the folder
# $4 is the name of the feed
[ ! -f "$1" ] && exit 1
[ ! -d "$2" ] && mkdir -p "$2"
[ ! -d "$2" ] && exit 1
[ -z "$4" ] && f="feed.xml" || f="$4"
find "$2" \( -iname '*jpg' -o -iname '*jpeg' -o -iname '*png' -o -iname '*gif' \) -mtime +1 -delete
t="$2/$(basename "$1")"
cp -v "$1" "$t"
img_url="$3/$(basename "$1")"
echo "$img_url"
:>"$2/$f"
cat > "$2/$f" <<EOF
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Current Wallpaper</title>
<link>$3/</link>
<description>My most recent wallpaper</description>
<language>en-us</language>
<copyright/>
<pubDate>$(date -R)</pubDate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<atom:link href="$3/$f" rel="self" type="application/rss+xml"/>
<item>
<title>$(basename "$1")</title>
<link>$img_url</link>
<guid isPermaLink="false">urn:x-img:$(date +%s)</guid>
<pubDate>$(date -R)</pubDate>
<media:title type="plain">$(basename "$1")</media:title>
<media:rating>nonadult</media:rating>
<media:description type="html"><![CDATA[<p><img src="$img_url" /><br />$(basename "$1")</p>]]></media:description>
<media:content url="$img_url" height="$(identify -format '%h' "$t")" width="$(identify -format '%w' "$t")"/>
<description><![CDATA[<p><img src="$img_url" /><br />$(basename "$1")</p>]]></description>
</item>
</channel>
</rss>
EOF
<TaskerData sr="" dvi="1" tv="4.4u1m">
<Task sr="task6">
<cdate>1405876547716</cdate>
<edate>1405903484508</edate>
<id>6</id>
<nme>Random Wallpaper Switch</nme>
<pri>10</pri>
<Action sr="act0" ve="6">
<code>547</code>
<Str sr="arg0" ve="3">%wallfold</Str>
<Str sr="arg1" ve="3">%WALLPAPERDIR</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act1" ve="6">
<code>131</code>
<Str sr="arg0" ve="3">Tasker/scripts/wallpaper_switch.js</Str>
<Str sr="arg1" ve="3"/>
<Int sr="arg2" val="1"/>
<Int sr="arg3" val="45"/>
</Action>
<Img sr="icn" ve="2">
<nme>cust_flag</nme>
</Img>
</Task>
</TaskerData>
var files = listFiles(wallfold, false).split("\n");
var number = Math.floor(Math.random() * (files.length));
var wf = files[number];
setGlobal('WALLPAPERFILE',wf);
setWallpaper(wf);
flash("Set Wallpaper: " + wf);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment