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:
Get Settings Keys
settings.keys.sort().join("\n")
Here are the resulting keys in OmniFocus 4.3:
- ContextModeShowsParents
- DefaultDueTime
- DefaultFloatingTimeZone
- DefaultScheduledNotificationTime
- DefaultStartTime
- DueSoonGranularity
- DueSoonInterval
- ForecastAllowCustomOrder
- ForecastFlatListCustomOrder
- ForecastSectionedListCustomAlarmsSectionCustomOrder
- ForecastSectionedListDeferSectionCustomOrder
- ForecastSectionedListDueSectionCustomOrder
- ForecastSectionedListFlaggedSectionCustomOrder
- InboxIsActive
- MacGlobalLayoutSettings
- MacInspectorConfigurationState
- MacQuickEntryLayoutSettings
- NearbyShowMapViewFirst
- OFMAutomaticallyHideCompletedItems
- OFMCompleteWhenLastItemComplete
- OFMDefaultSingletonProjectPersistentIdentifier
- OFMRemoteNotificationGroupID
- OFMRemoteNotificationGroupIDLastRegenerationDate
- OFMRemoteNotificationsDisabled
- OFMRequiredRelationshipToProcessInboxItem
- OFMStandardModePerspectiveIdentifierChanged
- OFMStandardModePerspectiveIdentifierCompleted
- OFMTaskDefaultSequential
- PadGlobalLayoutSettings
- PadInspectorConfigurationState
- PadQuickEntryLayoutSettings
- PerspectiveOrder_v3
- PhoneGlobalLayoutSettings
- PhoneInspectorConfigurationState
- PhoneQuickEntryLayoutSettings
- ProcessFlaggedItemsv2
- ProcessForecastv2
- ProcessInboxv2
- ProcessNearbyv4
- ProcessProjectsv2
- ProcessReviewv2
- ProcessTagsv3
- ProjectInfoReviewRepetitionString
- ReminderCalendarAlarmIndex
- ReminderCalendarExportEnabled
- UseNewHomeScreenAnimations
- VisionGlobalLayoutSettings
- VisionInspectorConfigurationState
- VisionQuickEntryLayoutSettings
- XMLVersionUpgradeLog
- _ForecastAllowCustomOrder
- _ForecastBlessedTagIdentifier
- _ForecastIncludeDeferredItems
- _ForecastIncludeItemsWithScheduledNotifications
- _ForecastIncludesInboxEvenWhenFocused
- _ForecastIncludesOnHoldItems
- _ForecastIsOrganizedIntoGroups
- _ForecastShouldPreserveHierarchy
- _ForecastTodayIncludesFlaggedItems
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:
defaultObjectForKey(key:String) → (Object or null) • Get the default value for the setting. The value may be a Boolean, String, or other class.
hasNonDefaultObjectForKey(key:String) → (Boolean) • Returns true if the current value for the setting is not its default value.
objectForKey(key:String) → (Object or null) • Returns the current value for the setting whose key matches the passed-in string.
setObjectForKey(value:Object or null, key:String) → ( ) • Set the value for the setting.
boolForKey(key:String) → (Boolean) • Used to retrieve the value of a setting whose value is a boolean.
setBoolForKey(value:Boolean, key:String) → ( ) • Used to set the value of setting whose value is a boolean.
integerForKey(key:String) → (Number) • Used to retrieve the value of a setting whose value is an integer.
setIntegerForKey(value:Number, key:String) → ( ) • Used to set the value of a setting whose value is an integer.
Examples
Here are some example scripts for accessing and changing settings values:
Get|Set Key Value
settings.objectForKey('InboxIsActive')
//--> true
settings.defaultObjectForKey('InboxIsActive')
//--> true
settings.boolForKey('InboxIsActive')
//--> true
settings.setBoolForKey(false, 'InboxIsActive')
settings.boolForKey('InboxIsActive')
//--> false
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