×

Database Settings

Settings represent the database synchronized configuration values.

NOTE: editing these should be done with care, as storing invalid values may corrupt your database or produce instability in the various client applications.

Settings Keys

Each of the database settings is represented by a key string. Here’s a script for accessing a list of the database keys:

omnifocus://localhost/omnijs-run?script=try%7Bconsole%2Elog%28settings%2Ekeys%2Esort%28%29%2Esort%28%29%2Ejoin%28%22%5Cn%22%29%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Get Settings Keys


settings.keys.sort().join("\n")

Here are the resulting keys:

Settings Functions

The value of the database settings are accessed and altered by using the following functions, passing in the target key string as a function parameter.

Here are the settings functions:

Examples

Here are some example scripts for accessing and changing settings values:

console.log("objectForKey: ", settings.objectForKey('InboxIsActive')) console.log("defaultObjectForKey: ", settings.defaultObjectForKey('InboxIsActive')) console.log("boolForKey: ", settings.boolForKey('InboxIsActive')) settings.setBoolForKey(false,'InboxIsActive') console.log("setBoolForKey: false") console.log("boolForKey: ", settings.boolForKey('InboxIsActive'))
omnifocus://localhost/omnijs-run?script=try%7Bconsole%2Elog%28%22objectForKey%3A%20%22%2C%20settings%2EobjectForKey%28%27InboxIsActive%27%29%29%0Aconsole%2Elog%28%22defaultObjectForKey%3A%20%22%2C%20settings%2EdefaultObjectForKey%28%27InboxIsActive%27%29%29%0Aconsole%2Elog%28%22boolForKey%3A%20%22%2C%20settings%2EboolForKey%28%27InboxIsActive%27%29%29%0Asettings%2EsetBoolForKey%28false%2C%27InboxIsActive%27%29%0Aconsole%2Elog%28%22setBoolForKey%3A%20false%22%29%0Aconsole%2Elog%28%22boolForKey%3A%20%22%2C%20settings%2EboolForKey%28%27InboxIsActive%27%29%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Get|Set Key Value


settings.objectForKey('InboxIsActive') //--> true settings.defaultObjectForKey('InboxIsActive') //--> true settings.boolForKey('InboxIsActive') //--> true settings.setBoolForKey(false, 'InboxIsActive') settings.boolForKey('InboxIsActive') //--> false
omnifocus://localhost/omnijs-run?script=try%7BtargetKey%20%3D%20%27InboxIsActive%27%0AdefaultValue%20%3D%20settings%2EdefaultObjectForKey%28targetKey%29%0Asettings%2EsetBoolForKey%28defaultValue%2C%20targetKey%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Restore Setting to Default (Boolean) Value


var targetKey = 'InboxIsActive' var defaultValue = settings.defaultObjectForKey(targetKey) settings.setBoolForKey(defaultValue, targetKey)

Here's a script demonstrating how to get and set the value of the start time setting:

Default Start Time Setting


settings.defaultObjectForKey('DefaultStartTime') //--> "00:00" settings.objectForKey('DefaultStartTime') //--> "00:00" settings.setObjectForKey('01:00','DefaultStartTime') //--> "01:00" //--> How to reset time setting to default value defaultValue = settings.defaultObjectForKey('DefaultStartTime') settings.setObjectForKey(defaultValue,'DefaultStartTime')

Here's a script demonstrating how to get and set the granularity value of the due soon setting:

Due Soon Granularity Setting


settings.defaultObjectForKey('DueSoonGranularity') //--> 1 settings.integerForKey('DueSoonGranularity') //--> 1 settings.setIntegerForKey(0,'DueSoonGranularity') //--> 0 defaultValue = settings.defaultObjectForKey('DueSoonGranularity') settings.setIntegerForKey(defaultValue,'DueSoonGranularity')

Using Default Deferment Settings

This plug-in shows how to use the default deferment settings to increase the defer date of the selected task one day. Select the DOWNLOAD PLUG-IN button to download a pair of plug-ins: Defer Task +1 Day, Defer Task -1 Day

Defer Task +1 Day
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.defer-task-plus-one-day", "version": "1.0", "description": "This plug-in will increase the deferment of the selected task by one day.", "label": "Defer Task +1 Day", "shortLabel": "Defer Task +1d" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: tasks, projects, folders, tags, databaseObjects, allObjects var task = selection.tasks[0] var currentDeferDate = task.deferDate if (currentDeferDate){ var dc = new DateComponents() dc.day = dc.day + 1 var targetDate = Calendar.current.dateByAddingDateComponents(currentDeferDate, dc) task.deferDate = targetDate } else { var startTime = settings.objectForKey('DefaultStartTime') //--> "00:00:00" var timeElements = startTime.split(":") var now = new Date() var currentDeferDate = Calendar.current.startOfDay(now) var dc = new DateComponents() dc.day = dc.day + 1 dc.hour = Number(timeElements[0]) dc.minutes = Number(timeElements[1]) dc.seconds = Number(timeElements[2]) var targetDate = Calendar.current.dateByAddingDateComponents(currentDeferDate, dc) task.deferDate = targetDate } }); action.validate = function(selection, sender){ // validation code // selection options: tasks, projects, folders, tags, databaseObjects, allObjects return (selection.tasks.length === 1) }; return action; })();