Toggle account sync?

1,531 views
Skip to first unread message

Michael A

unread,
Jan 21, 2015, 6:42:18 PM1/21/15
to tas...@googlegroups.com
Just downloaded tasker and am a bit overwhelmed. I'd like to create a profile so that at a certain time of day, if plugged in, synching on certain accounts is enabled. So that, for example, synching on Google calendar is only enabled for a limited time. Could someone give me a little guidance? Thanks!

Wietse van Buitenen

unread,
Jan 22, 2015, 7:11:42 AM1/22/15
to tas...@googlegroups.com
Hi,

Tasker itself "only" has the option to change global auto sync, not specific accounts.
You have a few options:
- install a plugin that has this feature (might cost money)
- use the new Java code functionality in Tasker 4.6 (is free but more advanced)

I did some config last week that has the needed Java stuff to enabled or disable specific items from an account (like Google Calendar, mail, contacts, ..).
I just need to document it and post it here on the forum.
It should be as easy as importing a Task and changing the e-mail address.

I hope to do this before/during the weekend.
I will post the link here when it's done.

Scott

unread,
Jan 22, 2015, 9:17:51 AM1/22/15
to tas...@googlegroups.com
I use Synker for that.  If you want to control what apps are synced with auto sync then it will cost money.  However, you can force sync accounts with the free version.  For example, with the free version I can manually stop auto sync from syncing my Gmail, but then force it to sync ever 30 minutes if some certain condition is met.  With the paid version I can choose what apps/accounts will auto sync when certain conditions are met.

This was all before any of the Java stuff was announced, so that may be a better solution.

Don D

unread,
Jan 22, 2015, 9:27:49 AM1/22/15
to tas...@googlegroups.com
That would be great of you to post Wietse.  I have the premium version of Synker, and while it's great in theory it doesn't work well in practice.  Syncing specific accounts returns constant errors, etc.  Synker hasn't been updated since July 2013, and I'm not alone in documenting its problems with KitKat.  I'm glad Scott is having good luck with it, but I'd strongly recommend avoiding Synker.

Wietse van Buitenen

unread,
Jan 22, 2015, 12:50:47 PM1/22/15
to tas...@googlegroups.com
I'm also using Synker and while I don't have too much issues with it, I find the UI confusing and the lack of updates worries me bit.
Since the API hasn't changed since then, an update isn't really needed though.

I prefer to do things with Tasker without too much external things :)
I will post so start example here soon as I might not get to writing out the full stuff the next days..

Wietse van Buitenen

unread,
Jan 22, 2015, 2:17:27 PM1/22/15
to tas...@googlegroups.com
here we go..
You can download SetSync.tsk.xml and import it in Tasker (Task - Import).
Next you need to change mym...@gmail.com by your Gmail address.
Now you can enable or disable the item you want to change (Variable Set %auth), you can only change 1 thing in this Task as it's just an example..
It cntains the needed info to enable/disable Google Calendar, Mail & Contacts sync.
Click the Play button to run the Task and you're set, the setting has changed.

this is the exported description:
<from AccountManager>
A1: Variable Set [ Name:%name To:mym...@gmail.com Do Maths:Off Append:Off ]
<from AccountManager or SyncAdapterType>
A2: Variable Set [ Name:%type To:com.google Do Maths:Off Append:Off ]
A3: Java Function [ Return:myaccount Class Or Object:Account Function:new
{Account} (String, String) Param:%name Param:%type Param: Param: Param: Continue Task After Error:On ]
<from SyncAdapterType - Mail>
A4: Variable Set [ Name:%auth To:gmail-ls Do Maths:Off Append:Off ]
<from SyncAdapterType - Calendar>
A5: [X] Variable Set [ Name:%auth To:com.android.calendar Do Maths:Off Append:Off ]
<from SyncAdapterType - Contacts>
A6: [X] Variable Set [ Name:%auth To:com.android.contacts Do Maths:Off Append:Off ]
<This makes sure the item is visible in accounts (don't set this to 0)>
A7: Java Function [ Return:%sync Class Or Object:ContentResolver Function:setIsSyncable
{} (Account, String, int) Param:myaccount Param:%auth Param:1 Param: Param: Continue Task After Error:On ]
<Enable>
A8: Java Function [ Return:%sync Class Or Object:ContentResolver Function:setSyncAutomatically
{} (Account, String, boolean) Param:myaccount Param:%auth Param:true Param: Param: Continue Task After Error:On ]

you can get info on other accounts by using the GetSyncAdapters.tsk.xml attached.
The %name variable needs to be extracted from AccountManager which needs to be done with a kid app but I'll explain that in another post when I get to it.
Mostly you can get %name somewhere from looking at the accounts on your device..

I'll also add the exported description from GetSyncAdapters.tsk.xml:
A1: Java Function [ Return:%sat Class Or Object:ContentResolver Function:getSyncAdapterTypes
{SyncAdapterType[]} () Param: Param: Param: Param: Param: Continue Task After Error:On ]
A2: Flash [ Text:%sat(#) %sat() Long:Off ]

this should get you started..

On Thursday, January 22, 2015 at 3:27:49 PM UTC+1, Don D wrote:
SetSync.tsk.xml
GetSyncAdapters.tsk.xml

Michael A

unread,
Jan 23, 2015, 3:57:47 PM1/23/15
to tas...@googlegroups.com
Looks good, I think,but I'm not sure how to enable or disable  the relevant variable .
"Now you can enable or disable the item you want to change (Variable Set %auth)".
 Thanks for the help.

Wietse van Buitenen

unread,
Jan 23, 2015, 4:53:06 PM1/23/15
to tas...@googlegroups.com
click and hold the action (Variable Set) and then click the disable button (looks like a power button)..
by default, the "gmail-ls" is enabled and the others are disabled..

Michael A

unread,
Jan 23, 2015, 5:56:16 PM1/23/15
to tas...@googlegroups.com
Nice, thanks! This should get me started, I'm going to play around with this and try to make a profile. Certainly none of this interface is very intuitive .

Michael A

unread,
Jan 23, 2015, 8:33:07 PM1/23/15
to tas...@googlegroups.com
Ok, looks like I need a way to selectively unsync those accounts as well. Can you do that through that script?

Robert Ryan

unread,
Jan 23, 2015, 9:21:01 PM1/23/15
to tas...@googlegroups.com
As an alternative you could use the Autoinput plug-in ($1.35). As an example, this task toggles the auto-sync on my Google Calendar:

Test (18)
A1: Sync Settings
A2: AutoInput Action [ Configuration:Type: Text
Value: rbr...@gmail.com
Action : Click Package:com.joaomgcd.autoinput Name:AutoInput Action Timeout (Seconds):20 ]
A3: Wait [ MS:250 Seconds:0 Minutes:0 Hours:0 Days:0 ]
A4: AutoInput Action [ Configuration:Type: Text
Value: Calendar
Action : Click Package:com.joaomgcd.autoinput Name:AutoInput Action Timeout (Seconds):20 ]
A5: Wait [ MS:250 Seconds:0 Minutes:0 Hours:0 Days:0 ]
A6: AutoInput Global Action [ Configuration:Action: Back Package:com.joaomgcd.autoinput Name:AutoInput Global Action Timeout (Seconds):20 ]

Wietse van Buitenen

unread,
Jan 24, 2015, 4:40:21 AM1/24/15
to tas...@googlegroups.com
It's not intuitive because it's slightly beyond beginner stuff and you're just starting, it will grow on you :)

Wietse van Buitenen

unread,
Jan 24, 2015, 4:45:19 AM1/24/15
to tas...@googlegroups.com
sure..
just open Java Function - ContentResolver.setSyncAutomatically and change the value for Param (boolean) from true to false

The whole thing will become more useful if you use If and Else stuff from Tasker - add Action - Tasks..
You can then create a Task which you can call from other Tasks.

Michael A

unread,
Jan 24, 2015, 12:35:34 PM1/24/15
to tas...@googlegroups.com

Ok, well I think I got it working, though I'm not sure, and this probably isn't the most efficient way to do it. I created a profile with a time and power(on a.c.) context. I then made an enter task (sync on) and exit task (sync off). The sync on task was several nested tasks: WiFi on, sync contacts on, sync calendar on. The latter 2 tasks were modified versions of your java tasks. Similarly, the exit task was sync contacts off, sync calendar off, WiFi off. I'd like to export the whole routine for others to check/use, but when I try to export the profile it looks like it refers to my tasks (rather than showing the actions that the tasks perform), so isn't of much use. Thanks for all the help so far, this is an interesting learning experience for a non-programmer. And now that I think about it, I might as well take the time context out of it, and just have it sync on ac power...

Wietse van Buitenen

unread,
Jan 25, 2015, 5:28:49 AM1/25/15
to tas...@googlegroups.com
Glad you got it working :)

The Task I posted was the beginning, I now modified it for general use.
I attached the new version, you can call this task and enable or disable sync for several items of 1 type.
Call this Task from another Task with Perform Task and following settings:
Priority (to make sure it completes before the calling Task continues): %priority + 1
Parameter 2: gmail-ls,com.android.calendar,com.android.contacts

Regarding Exporting your items together, you need to put them in a Project:
http://tasker.dinglisch.net/userguide_summary.html#projects
Then all referenced Tasks and everything in the Project is Exported.
SetSync.tsk.xml

Wietse van Buitenen

unread,
Jan 27, 2015, 7:19:24 AM1/27/15
to tas...@googlegroups.com
Here the list of Google services on my phone, you can use the value of the %auth column (only when userVisible is 1)..


Name (in Accounts)

%auth to use

userVisible

Gmail

gmail-ls

1

Calendar

com.android.calendar

1

Contacts

com.android.contacts

1

Keep

com.google.android.keep

1

Google Play Music

com.google.android.music.MusicContent

1

Google Play Movies & TV

com.google.android.videos.sync

1

Google Play Newsstand

com.google.android.apps.magazines

1

Google Play Books

com.google.android.apps.books

1

Drive

com.google.android.apps.docs

1

Docs

com.google.android.apps.docs.editors.kix

1

Sheets

com.google.android.apps.docs.editors.trix

1

Chrome Beta

com.chrome.beta

1

People Details

com.google.android.gms.people

1

App Data

com.google.android.gms.appstate

1

Google+

com.google.android.apps.plus.content.EsProvider

1

Google+ Uploads

com.google.android.apps.plus.iu.EsGoogleIuProvider

1

Google+ Photos

com.google.android.apps.photos.GooglePhotoDownsyncProvider

1

Google Photos Auto Backup

com.google.android.gms.photos.iu.EsGoogleIuProvider

1

Google Fit data

com.google.android.gms.fitness

1

Sound Search for Google

com.google.android.ears.heard.EarsContentProvider

1

News & Weather

com.google.android.apps.genie.geniewidget

1





com.google.android.gms.plus.action

0


com.google.android.gms.reminders

0


com.google.android.gms.games.background

0


com.google.android.apps.cloudprint.cloudprintprovider

0


subscribedfeeds

0


com.google.android.gms.drive.sync

0


com.google.android.location.reporting

0


com.google.android.gms.auth.confirm

0


com.google.android.gms.games

0


com.google.android.gms.kids.timeouts

0

Roberto Fabrizi

unread,
Jan 27, 2015, 8:56:10 AM1/27/15
to tas...@googlegroups.com
Do you mean that we can't deactivate user invisible ones? I remember that with Greenify + xposed framework you could unhide the hidden ones and deselect them.
I see many hidden ones on my phone, you think that it wont work with those? 
Cheers!


On Tuesday, January 27, 2015 at 1:19:24 PM UTC+1, Wietse van Buitenen wrote:
Here the list of Google services on my phone, you can use the value of the %auth column (only when userVisible is 1)..
...

Roberto Fabrizi

unread,
Jan 27, 2015, 9:03:58 AM1/27/15
to tas...@googlegroups.com
As a quick side note this is working flawlessly for non google stuff like whatsapp too ;)

Wietse van Buitenen

unread,
Jan 28, 2015, 10:17:03 AM1/28/15
to tas...@googlegroups.com
I should indeed have clarified that this was what I thought wouldn't work, I didn't fully test the userVisible = 0 ones..
I tested by setting userVisible to 1 but that didn't work so I assumed that enabling or disabling sync wouldn't work either..
If you get a chance to test it you can always post your findings here..

Good to hear it's working with WhatsApp too.

I created the Task on my Z1 (4.4.4), exported it and imported it on my N7 (5.0.2) and there it also works without modification so I assume this method will work for some time in the future :)


On Tuesday, January 27, 2015 at 2:56:10 PM UTC+1, Roberto Fabrizi wrote:

Roberto Fabrizi

unread,
Jan 28, 2015, 2:38:16 PM1/28/15
to tas...@googlegroups.com
It seems that it wont work. For shazam I have these two entries:

SyncAdapterType {name=com.shazam.android.persistence.providers.NewsSummarySyncStubContentProvider, type=com.shazam.android, userVisible=false, supportsUploading=true, isAlwaysSyncable=true, allowParallelSyncs=false, settingsActivity=null},

and 

SyncAdapterType {name=com.shazam.android.persistence.providers.TrackSyncStubContentProvider, type=com.shazam.android, userVisible=false, supportsUploading=true, isAlwaysSyncable=true, allowParallelSyncs=false, settingsActivity=null},

I made this profile:

<TaskerData sr="" dvi="1" tv="4.6u3m">
<Task sr="task77">
<cdate>1422367003298</cdate>
<edate>1422473675761</edate>
<id>77</id>
<nme>Set Sync Test</nme>
<pri>10</pri>
<Action sr="act1" ve="7">
<code>130</code>
<Str sr="arg0" ve="3">SetSync</Str>
<Int sr="arg1">
<var>%priority + 1</var>
</Int>
<Str sr="arg2" ve="3">Sync|com.shazam.android|0</Str>
<Str sr="arg3" ve="3">com.shazam.android.persistence.providers.TrackSyncStubContentProvider,zam.android.persistence.providers.NewsSummarySyncStubContentProvider</Str>
<Str sr="arg4" ve="3"/>
<Int sr="arg5" val="0"/>
</Action>
</Task>
</TaskerData>

But nothing happens :(

Roberto Fabrizi

unread,
Jan 28, 2015, 2:39:07 PM1/28/15
to tas...@googlegroups.com
Also tried using 

<Str sr="arg2" ve="3">Shazam|com.shazam.android|0</Str>

instead of 

Roberto Fabrizi

unread,
Jan 29, 2015, 4:47:15 PM1/29/15
to tas...@googlegroups.com
Although surely not related to the script that you posted Wietse, I noticed that Whatsapp reactivates its sync after a while, so irritating....

Roberto Fabrizi

unread,
Feb 6, 2015, 8:23:19 AM2/6/15
to tas...@googlegroups.com
Would be helpful to find out if there is a way to know when the last sync has occurred, or if a sync has finished...

Robert Ryan

unread,
Feb 6, 2015, 9:46:27 AM2/6/15
to tas...@googlegroups.com
Another place where Autoinput is useful.

Open the sync settings for the app. The date of last sync is displayed there. Use Autoinput's 'UI Query' action to get the string containing the date into a Tasker variable. That string also tells you if the sync is finished or not.
Reply all
Reply to author
Forward
0 new messages