Automatically restrict apps background data using Tasker
"Restrict background data" seems to restrict apps from accessing the network unless they're in the foreground, i.e. visible on the screen.

On Tasker version 4.5u1m for Android 4+, I don't see anything relevant in the Net action category, which is where I'd expect to find something about network access. The Settings action category is just for showing settings dialogs, so it wouldn't be there.

You could turn that "restrict background data" setting on, and then auto-launch any application that you want to update/sync given a particular parameter (e.g. launch music app when headset inserted, only changed to something like launch google play when I'm signed into a wireless network). Basically you'd be using tasker to put something in the foreground, not switch the setting.

You can also limit syncing, which is one kind of background data.