×

Database Settings

Settings represent the database synchronized configuration values.

NOTE: editing settings 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 in OmniFocus 4.3:

Here’s a script to log the current keys and their corresponding values:

View Keys and Values


keys = settings.keys.sort() keys.forEach(key => { value = settings.objectForKey(key) if(typeof value !== String){ console.log(key, JSON.stringify(value)) } else { console.log(key, value) } })

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


targetKey = 'InboxIsActive' 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.1", "description": "This plug-in will increase the deferment of the selected task by one day.", "label": "Defer Task +1 Day", "shortLabel": "Defer Task +1d", "paletteLabel": "Defer Task +1d", "image": "24.square" }*/ (() => { const action = new PlugIn.Action(function(selection, sender){ // action code // selection options: tasks, projects, folders, tags, databaseObjects, allObjects task = selection.tasks[0] currentDeferDate = task.deferDate if (currentDeferDate){ dc = new DateComponents() dc.day = dc.day + 1 targetDate = Calendar.current.dateByAddingDateComponents(currentDeferDate, dc) task.deferDate = targetDate } else { startTime = settings.objectForKey('DefaultStartTime') //--> "00:00:00" timeElements = startTime.split(":") now = new Date() currentDeferDate = Calendar.current.startOfDay(now) dc = new DateComponents() dc.day = dc.day + 1 dc.hour = Number(timeElements[0]) dc.minutes = Number(timeElements[1]) dc.seconds = Number(timeElements[2]) 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; })();

Creating a new OmniFocus task due tomorrow at the default due time:

New Task for Tomorrow


defaultDueTime = settings.defaultObjectForKey('DefaultDueTime') timeElements = defaultDueTime.split(":") dateObj = Calendar.current.startOfDay(new Date()) duration = new DateComponents() duration.day = 1 duration.hour = parseInt(timeElements[0]) duration.minute = parseInt(timeElements[1]) targetDateObj = Calendar.current.dateByAddingDateComponents(dateObj,duration) task = new Task("My New Task") task.dueDate = targetDateObj