Skip to content

Instantly share code, notes, and snippets.

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 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/ "$3" /path/to/wallpaper

In this line, make sure to use the right /path/to/ /path/to/wallpaper should be the path on your filesystem to the folder where your web-accessible images will be stored. 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 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
  • %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">
<nme>Download From Rss</nme>
<Action sr="act0" ve="6">
<Str sr="arg0" ve="3"></Str>
<Int sr="arg1" val="0"/>
<Str sr="arg2" ve="3">%WALLPAPERDIR,%WALLPAPERFEED</Str>
<Img sr="icn" ve="2">
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]
u = droid.getIntent().result[u'extras'][u'%WALLPAPERFEED']
u = None
if (len(sys.argv) > 2):
p = sys.argv[2]
p = droid.getIntent().result[u'extras'][u'%WALLPAPERDIR']
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)
# $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"
cat > "$2/$f" <<EOF
<rss version="2.0" xmlns:media="" xmlns:atom="">
<title>Current Wallpaper</title>
<description>My most recent wallpaper</description>
<pubDate>$(date -R)</pubDate>
<atom:link href="$3/$f" rel="self" type="application/rss+xml"/>
<title>$(basename "$1")</title>
<guid isPermaLink="false">urn:x-img:$(date +%s)</guid>
<pubDate>$(date -R)</pubDate>
<media:title type="plain">$(basename "$1")</media:title>
<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>
<TaskerData sr="" dvi="1" tv="4.4u1m">
<Task sr="task6">
<nme>Random Wallpaper Switch</nme>
<Action sr="act0" ve="6">
<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 sr="act1" ve="6">
<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"/>
<Img sr="icn" ve="2">
var files = listFiles(wallfold, false).split("\n");
var number = Math.floor(Math.random() * (files.length));
var wf = files[number];
flash("Set Wallpaper: " + wf);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment