Script to add new calendars

Hi

I’ve created a small script to allow you to easily add new calendars to SailfishOS:

AddCalendars.zip

It must be run from the terminal as root, because it directly modifies the Calendar database. Here is what it looks like:

[defaultuser@MyPhone ~]$ devel-su
Password:
[root@MyPhone ~]# ./AddCalendars.py 


(*)

After making any changes, you will need to close the Calendar app. When you restart it, the new calendars will be available.

For some reason, all newly added calendars are called “Personal”, but underneath it shows their description - which I’ve set to the name you chose. I suspect it’s called “Personal” due to the value of the Flags field I’ve set, but unfortunately this seems to be undocumented, so I had to use the value that someone else said to use.

Each time you run the script, it backs-up the current Calendar database to “/root/Calendar_backup.db”, although I don’t expect any problems, because it first checks the database’s structure looks right. But if you DO have any serious Calendar problems, please do NOT run the script again until you have renamed the backup file (so it doesn’t get overwritten).

  • = Unfortunately SfOS’s built-in terminal doesn’t handle 24-bit ANSI colour codes, so you won’t see any coloured squares in that case. But I find it easier to SSH into the phone from my PC for stuff like this, and so in that case the colours are visible.
12 Likes

The calendar database is a user file, no need to be root to run the script. But indeed, the database file is not readable/writable by the user, but by a “privileged” user. To do this, instead of devel-su (which give you root access on all files in your phone), issue devel-su -p instead. This will give you access to the user files, within the privileged group.

6 Likes

Thanks. I’ve updated the script to prefer & be compatible with the Privileged user:
AddCalendars.zip

If you run it as the normal user, it will offer to run itself using “devel-su -p”. And it now backs-up to the “/home/defaultuser” folder instead.

So now you should just run it directly:

[defaultuser@MyPhone ~]$ ./AddCalendars.py 

Or like so:

[defaultuser@MyPhone ~]$ devel-su -p ./AddCalendars.py 
1 Like

Beware that deleting a calendar after you’ve added/imported events to it seems to cause problems, so I strongly advise against this. So it’s better to just restore the backup of the database from before you added any calendars, or at least from before you added any events.

1 Like

I’ve updated my script again:
AddCalendars.zip

Deleting calendars that contain events should now work correctly. (Previously it deleted the calendar but not the events it contained, leading to orphaned events. Now it deletes all events associated with that calendar.)

I’ve also made my script less sensitive to changes in database structure - it should now only complain if something it needs is missing.

1 Like

I’ve updated my script again:
AddCalendars.zip

It now has the option to delete just the contents of a calendar (leaving an empty calendar).

1 Like

Why not make it a patch to add it to the pull down menu?

1 Like

I have no idea about & have never used any “patches”. I’m more likely to make it into a stand-alone app, when I get time…