The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniOutliner 3 for Mac (http://forums.omnigroup.com/forumdisplay.php?f=9)
-   -   Can you create sequential dates? (http://forums.omnigroup.com/showthread.php?t=22921)

FredH 2011-12-19 07:08 PM

Can you create sequential dates?
 
I'm guessing there's no copying function for columns like in Excel, but is there a way to create a column and have it fill in sequential dates?

RobTrew 2011-12-20 10:31 AM

You could assign a script to a keystroke or toolbar button.

If, for example, you select a date or number column by clicking on its header (so that the whole column has a blue highlight) the following script will fill the cells of all rows with values derived from those of the first one or two rows.

(The difference between row values defaults to one day (or 1.0) but if row 2 already contains a value when the script is run, the series will continue the interval/difference between rows 1 and 2).

[CODE]-- FILL DATE OR NUMBER COLUMN WITH VALUES
-- BASED ON THE VALUES IN THE FIRST ONE OR TWO ROWS

tell application id "OOut"
if (count of documents) < 1 then return
tell front document
set lngRows to count of rows
if lngRows < 3 then return
set lstSeldCols to selected columns
if (count of lstSeldCols) < 1 then return
set {eType, idCol} to {type, id} of first item of lstSeldCols

if eType is not in {number, date} then return
set {varStart, varNext} to {value of cell id idCol of row 1, value of cell id idCol of row 2}

if eType = number then
if varNext is missing value then
set varDelta to 1
set iStart to 2
else
set iStart to 3
set varDelta to varNext - varStart
end if

-- FILL REMAINING CELLS WITH NUMBERES
repeat with i from iStart to count of rows
set value of cell id idCol of row i to varStart + (varDelta * (i - 1))
end repeat
else -- date
if varNext is missing value then
set varDelta to 1
set iStart to 2
else
set varDelta to ((varNext - varStart) / days) as integer
set iStart to 3
end if

-- FILL REMAINING CELLS WITH DATES
repeat with i from iStart to lngRows
set value of cell id idCol of row i to varStart + (varDelta * (i - 1) * days)
end repeat
end if
end tell
end tell[/CODE]

RobTrew 2011-12-20 11:05 AM

Or, if you need to select only a subset of rows to fill (rather than selecting and filling a whole column) something like the following:

[CODE]property pTitle : "Fill rows with dates/numbers"
property pVer : "0.2"

-- FILL DATE OR NUMBER COLUMN WITH VALUES
-- BASED ON THE VALUES IN THE FIRST ONE OR TWO
-- SELECTED ROWS

tell application id "OOut"
if (count of documents) < 1 then return
tell front document
set lstRows to selected rows
set lngRows to count of lstRows
if lngRows < 3 then
display dialog ¬
"Select two or more rows," & return & return & ¬
"(With at least a start value in the relevant column of the first selected row)." buttons "OK" default button "OK" with title pTitle & " " & pVer
return
end if

-- CHOOSE A DATE OR NUMBER COLUMN
set refCols to a reference to (columns where type is date or type is number)
if (count of refCols) < 1 then
display dialog ¬
"Requires at least one column of type date or number." buttons "OK" default button "OK" with title pTitle & " " & pVer
return
end if
set varChoice to choose from list (name of refCols) as list with prompt ¬
"Column to fill:" with title pTitle & " " & pVer
if varChoice is false then return
set oCol to column named (first item of varChoice)
set {eType, idCol} to {type, id} of oCol

-- GET VALUES FROM THE FIRST (AND PERHAPS SECOND) ROWS
set {varStart, varNext} to {value of cell id idCol of item 1 of lstRows, ¬
value of cell id idCol of item 2 of lstRows}

set varDelta to 1
set iStart to 2

if eType = number then
if varNext ≠ missing value then
set iStart to 3
set varDelta to varNext - varStart
end if

-- FILL REMAINING CELLS WITH NUMBERS
repeat with i from iStart to lngRows
set value of cell id idCol of item i of lstRows to varStart + (varDelta * (i - 1))
end repeat
else -- date
if varNext ≠ missing value then
set varDelta to ((varNext - varStart) / days) as integer
set iStart to 3
end if

-- FILL REMAINING CELLS WITH DATES
repeat with i from iStart to lngRows
set value of cell id idCol of item i of lstRows to varStart + (varDelta * (i - 1) * days)
end repeat
end if
end tell
end tell
[/CODE]

FredH 2011-12-20 01:42 PM

Wow, thanks. I think I used a script once in my life, if you could help me with instructions on how to use that code, I'd appreciate it.

RobTrew 2011-12-20 02:00 PM

[QUOTE=FredH;105299]instructions on how to use that code[/QUOTE]

I would start with the second of those two scripts, copying all of the script (making sure no lines get missed) and pasting it into the Applescript Editor application.

Thereafter, the instructions are the same as for running OmniFocus scripts, as summarized [URL="http://forums.omnigroup.com/showthread.php?t=7453"]here[/URL].


All times are GMT -8. The time now is 03:59 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.